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
#include<bits/stdc++.h>
#define INF -1e18
using namespace std;

const int M = 1000 * 1000 + 7;
long long ones[M] = {0,1,1,2, 1,2,2,3, 1,2,2,3, 2,3,3,4, 1,2,2,3, 2,3,3,4, 2,4,3,4, 3,4,4,5};
const int N = 207;
long long t[N];
vector<long long>v;
int n, m;	
long long ans = INF;

long long func() {
	long long sum = 0;
	for(int i = 0; i < n; i++) {
		sum += t[i] * ones[v[i]];
		if(i && v[i] < v[i-1]) {
			sum = 0;
			break;
		}
	}
	return sum;
}

int main() {
		
	ios_base::sync_with_stdio(0);
	cin >> n >> m;
	for(int i = 0; i <= m; i++) v.push_back(i);
	for(int i = 0; i < n; i++) cin >> t[i];
	
	do{
		ans = max(ans, func());
	} while(next_permutation(v.begin(), v.end()));
	
	cout << ans;
	return 0;
}