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
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for (int i = (a); i <= (b); ++i)
#define REPD(i,a,b) for (int i = (a); i >= (b); --i)
#define FORI(i,n) REP(i,1,n)
#define FOR(i,n) REP(i,0,int(n)-1)
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define SZ(x) int((x).size())
#define DBG(v) cerr << #v << " = " << (v) << endl;
#define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#define fi first
#define se second

const int BB = 61;
const int N = 202;
const ll inf = 4e17;

int n;
ll m;
ll sum[N][N], dp[BB][N][N], dp2[BB][N];
ll a[N];

int main() {
	scanf("%d%lld", &n, &m);
	FORI(i,n) scanf("%lld", &a[i]);
	for (int le = 1; le <= n; le++) {
		sum[le][le] = 0;
		for (int ri = le+1; ri <= n+1; ri++) {
			sum[le][ri] = sum[le][ri-1] + a[ri-1];
		}
	}
	FORI(le,n) {
		for (int ri=le+2;ri<=n+1;ri++) dp[0][le][ri] = -inf;
		dp[0][le][le+1] = 0;
	}
	for (int bits = 1; bits < BB; bits++) {
		int BL = bits > 10 ? n+5 : (1<<bits);
		FORI(L,n) {
			for (int le = 1; le+L <= n+1; le++) {
				int ri = le + L;
				dp[bits][le][ri] = -inf;
				if (L <= BL) {
					for (int mi = le; mi <= ri; mi++) {
						dp[bits][le][ri] = max(dp[bits][le][ri], dp[bits-1][le][mi] + dp[bits-1][mi][ri] + sum[mi][ri]);
					}
					//printf("dp[%d][%d][%d] = %lld\n", bits, le, ri, dp[bits][le][ri]);
				}
			}
		}
	}
	
	FORI(le,n) {
		dp2[0][le] = -inf;
	}
	dp2[0][n] = 0;
	for (int bits = 1; bits < BB; bits++) {
		int ri = n+1;
		FORI(le,n) {
			dp2[bits][le] = -inf;
			if (m & (1LL<<(bits-1))) {
				for (int mi = le; mi <= ri; mi++) {
					dp2[bits][le] = max(dp2[bits][le], dp[bits-1][le][mi] + dp2[bits-1][mi] + sum[mi][ri]);
				}
			} else {
				dp2[bits][le] = dp2[bits-1][le];
			}
			//printf("dp2[%d][%d] = %lld\n", bits, le, dp2[bits][le]);
		}
	}
	printf("%lld\n", dp2[BB-1][1]);
	return 0;
}