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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using ll=long long;
#define pb push_back
#define fst first
#define snd second
using vll=vector<ll>;
using Pii=pair<int,int>;
using Pll=pair<ll,ll>;
using vpii=vector<Pii>;
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#define sim template <class c
#define mor > muu & operator<<(
#define ris return *this
#define R22(r) sim> typename enable_if<1 r sizeof(dud<c>(0)),muu&>::type operator<<(c g) {
sim> struct rge {c b, e;};
sim> rge<c> range(c i, c j) {return rge<c>{i, j};}
sim> auto dud(c*r)->decltype(cerr << *r);
sim> char dud(...);
struct muu {
	#ifdef LOCAL
	stringstream a;
	~muu() {cerr << a.str() << endl;}
	R22(<) a << boolalpha << g; ris;}
	R22(==) ris << range(begin(g), end(g));}
	sim mor rge<c> u) {
		a << "[";
		for (c i = u.b; i != u.e; ++i)
			*this << ", " + 2 * (i == u.b) << *i;
		ris << "]";
	}
	sim, class m mor pair<m,c> r) {ris << "(" << r.first << ", " << r.second << ")";}
	#else
	sim mor const c &){ris;}
	#endif
	muu & operator()(){ris;}
};
#define imie(r) "[" #r ": " << (r) << "] "
#define debug (muu() << __FUNCTION__ << "#" << __LINE__ << ": " )
typedef long long ll;
const int maxn = 300;
const ll inf = 1e18;
ll A[maxn];
ll Apref[maxn];
ll n, m;
ll sum(int a, int b)
{
	if(a == 0)
		return Apref[b];
	else
		return Apref[b] - Apref[a-1];
}
ll dp[maxn][maxn][70][2];
bool jest[maxn][maxn][70][2];
ll jebaj_spam(int a, int b, int bity, bool glob);
ll jebaj(int a, int b, int bity, bool glob)
{
	if(b - a + 1 > (1ll << (bity)))
		return -inf;
	if(bity == 0)
		return 0;
	if(glob == true && (m & (1ll << (bity - 1))) == 0)
		return jebaj_spam(a, b, bity - 1, glob);
	ll res = max(jebaj_spam(a, b, bity - 1, false), jebaj_spam(a, b, bity - 1, glob) + sum(a,b));
	for(int c = a; c < b; ++c)
		res = max(res, jebaj_spam(a, c, bity - 1, false) + jebaj_spam(c + 1, b, bity - 1, glob) + sum(c + 1,b));
	return res;
}
ll jebaj_spam(int a, int b, int bity, bool glob)
{
	if(!jest[a][b][bity][glob])
	{
		jest[a][b][bity][glob] = true;
		dp[a][b][bity][glob] = jebaj(a, b, bity, glob);
	}
	return dp[a][b][bity][glob];
}
int main()
{
	scanf("%lld%lld", &n, &m);
	for(int i = 0; i < n; ++i)
		scanf("%lld", &A[i]);
	Apref[0] = A[0];
	for(int i = 1; i < n; ++i)
		Apref[i] = A[i] + Apref[i-1];
	printf("%lld\n", jebaj(0, n-1, 62, true));
}