#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MAXN 45
#define FOR(i, a, b) for(ll i = a; i <= b; i++)
ll n, c, m[MAXN], r = 1;
int main(){
cin >> n >> c;
FOR(i, 1, n) cin >> m[i];
sort(m + 1, m + 1 + n);
if(n == 1) {
cout << (m[1] <= c) << endl;
return 0;
}
pair<ll, ll> a = {1, (1 + n) / 2}, b = {(1 + n) / 2 + 1, n};
// solve first half
ll mska = pow(2, a.second - a.first + 1);
vector<ll> msa;
FOR(msk, 1, mska - 1){
ll s = 0;
FOR(i, a.first, a.second){
if(msk & (1 << (i - a.first))){
s += m[i];
}
}
if(s > c) continue;
r++;
msa.push_back(s);
}
sort(begin(msa), end(msa));
// solve second half
ll mskb = pow(2, b.second - b.first + 1);
vector<ll> msb;
FOR(msk, 1, mskb - 1){
ll s = 0;
FOR(i, b.first, b.second){
if(msk & (1 << (i - b.first))){
s += m[i];
}
}
if(s > c) continue;
r++;
msb.push_back(s);
}
sort(begin(msb), end(msb));
// combine both halves
ll na = (ll)msa.size(), nb = (ll)msb.size();
ll ptr = na - 1;
FOR(i, 0, nb - 1){
while(ptr >= 0 && msa[ptr] + msb[i] > c) {
ptr--;
}
r += ptr + 1;
}
cout << r << endl;
}
/*
8 1232
143 321241 53 1532 123 3253 32513 1232
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
2256 KB |
Output is correct |
2 |
Correct |
64 ms |
5312 KB |
Output is correct |
3 |
Correct |
259 ms |
21280 KB |
Output is correct |
4 |
Correct |
69 ms |
5308 KB |
Output is correct |
5 |
Correct |
11 ms |
1488 KB |
Output is correct |
6 |
Correct |
8 ms |
984 KB |
Output is correct |
7 |
Correct |
8 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
2888 KB |
Output is correct |
2 |
Correct |
23 ms |
2256 KB |
Output is correct |
3 |
Correct |
113 ms |
12216 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
6 ms |
984 KB |
Output is correct |
6 |
Correct |
16 ms |
1492 KB |
Output is correct |
7 |
Correct |
8 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
46 ms |
4300 KB |
Output is correct |
2 |
Correct |
102 ms |
8496 KB |
Output is correct |
3 |
Correct |
94 ms |
8500 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
69 ms |
8444 KB |
Output is correct |
6 |
Correct |
238 ms |
20908 KB |
Output is correct |
7 |
Correct |
48 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
203 ms |
16560 KB |
Output is correct |
2 |
Correct |
24 ms |
2256 KB |
Output is correct |
3 |
Correct |
7 ms |
984 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
6 ms |
984 KB |
Output is correct |
6 |
Correct |
203 ms |
16640 KB |
Output is correct |
7 |
Correct |
8 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
2252 KB |
Output is correct |
2 |
Correct |
66 ms |
5312 KB |
Output is correct |
3 |
Correct |
7 ms |
984 KB |
Output is correct |
4 |
Correct |
7 ms |
984 KB |
Output is correct |
5 |
Correct |
70 ms |
8120 KB |
Output is correct |
6 |
Correct |
25 ms |
2436 KB |
Output is correct |
7 |
Correct |
123 ms |
408 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
270 ms |
22444 KB |
Output is correct |
2 |
Correct |
27 ms |
2284 KB |
Output is correct |
3 |
Correct |
8 ms |
980 KB |
Output is correct |
4 |
Correct |
274 ms |
21680 KB |
Output is correct |
5 |
Correct |
95 ms |
12472 KB |
Output is correct |
6 |
Correct |
16 ms |
1492 KB |
Output is correct |
7 |
Correct |
16 ms |
344 KB |
Output is correct |