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
#include<iostream>
using namespace std;

long long tab[100000];
long long liczba = 0;
long long najw = 0;

void czy(long long m, long long n)
{
	long long s = m;
	for (long long z = 0; z < n; z++) {
		liczba = 0;
		for (long long l = 0; l < n; l++)
		{
			m = s;
			m -= l;
			for (long long j = m; j > n; j--)
			{
				long long k = 0;
				for (long long i = 128; i > 0; i /= 2)
				{
					if (m >= i)
					{
						k++;
						m -= i;
					}
				}
				liczba += k*tab[n - 1];
				if(najw < liczba){
                    najw = liczba;
				}
			}
		}
	}
	cout<<najw;
}


int main()
{
    ios::sync_with_stdio(0);
cin.tie(0);

    long long n,m;
    cin>>n>>m;
    for(long long i = 0; i<n; i++)
    {
        cin>>tab[i];
    }
    czy(m,n);
    return 0;
}