1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <bits/stdc++.h>
// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;

#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for (int i=(a); i<(b); ++i)
#define FORD(i,a,b) for (int i=(a)-1; i>=(b); --i)
#define MAX(dst,src) dst = max(dst, (src))

#define pb push_back
#define mp make_pair
#define st first
#define nd second

LL A[300];

LL DP[300][300][70][2];
const LL INF = (LL)1e17;

int main(int argc, char* argv[]) {
  int N;
  LL M;
  scanf("%d%lld", &N, &M);
  REP(i,N) scanf("%lld", &A[i]);
  REP(bits,63)REP(exact,2)REP(i,N)FOR(j,i+1,N+1) {
    DP[i][j][bits][exact] = -INF;
    if (bits == 0) {
      if (i+1 == j) DP[i][j][bits][exact] = 0;
      continue;
    }
    if (exact && !(M&(1LL<<(bits-1)))) {
      DP[i][j][bits][exact] = DP[i][j][bits-1][exact];
      continue;
    }
    LL added = 0;
    FORD(k,j+1,i) {
      MAX(DP[i][j][bits][exact], DP[i][k][bits-1][0] + DP[k][j][bits-1][exact] + added);
      if (k > i) added += A[k-1];
    }
  }
  printf("%lld\n", DP[0][N][62][1]);
}