#include <bits/stdc++.h>
using namespace std;
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
long long n; long long x; cin >> n >> x;
long long a1[n/2], a2[(n+1)/2];
for (auto& y : a1) cin >> y;
for (auto& y : a2) cin >> y;
vector<long long> half;
for (long long mask = 0; mask < 1 << (n/2); mask++) {
long long sum = 0;
for (long long i = 0; i < n/2; i++) {
if (mask & (1 << i)) {
sum += a1[i];
}
}
if (sum <= x) half.push_back(sum);
}
sort(half.begin(), half.end());
long long cnt = 0;
for (long long mask = 0; mask < (1 << ((n+1)/2)); mask++) {
long long sum = 0;
for (long long i = 0; i < (n+1)/2; i++) {
if (mask & (1 << i)) {
sum += a2[i];
}
}
if (sum <= x) cnt += upper_bound(half.begin(), half.end(), x - sum) - half.begin();
}
cout << cnt;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
980 KB |
Output is correct |
2 |
Correct |
95 ms |
3532 KB |
Output is correct |
3 |
Correct |
348 ms |
10692 KB |
Output is correct |
4 |
Correct |
91 ms |
3532 KB |
Output is correct |
5 |
Correct |
13 ms |
1152 KB |
Output is correct |
6 |
Correct |
7 ms |
724 KB |
Output is correct |
7 |
Correct |
8 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
1488 KB |
Output is correct |
2 |
Correct |
27 ms |
980 KB |
Output is correct |
3 |
Correct |
175 ms |
6600 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
6 ms |
724 KB |
Output is correct |
6 |
Correct |
14 ms |
980 KB |
Output is correct |
7 |
Correct |
8 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
63 ms |
1656 KB |
Output is correct |
2 |
Correct |
150 ms |
3700 KB |
Output is correct |
3 |
Correct |
126 ms |
3532 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
75 ms |
3532 KB |
Output is correct |
6 |
Correct |
208 ms |
10684 KB |
Output is correct |
7 |
Correct |
46 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
259 ms |
6600 KB |
Output is correct |
2 |
Correct |
25 ms |
980 KB |
Output is correct |
3 |
Correct |
8 ms |
724 KB |
Output is correct |
4 |
Correct |
1 ms |
500 KB |
Output is correct |
5 |
Correct |
6 ms |
724 KB |
Output is correct |
6 |
Correct |
150 ms |
6600 KB |
Output is correct |
7 |
Correct |
8 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
980 KB |
Output is correct |
2 |
Correct |
83 ms |
3548 KB |
Output is correct |
3 |
Correct |
8 ms |
724 KB |
Output is correct |
4 |
Correct |
8 ms |
892 KB |
Output is correct |
5 |
Correct |
84 ms |
3532 KB |
Output is correct |
6 |
Correct |
18 ms |
980 KB |
Output is correct |
7 |
Correct |
121 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
339 ms |
10684 KB |
Output is correct |
2 |
Correct |
27 ms |
1100 KB |
Output is correct |
3 |
Correct |
9 ms |
724 KB |
Output is correct |
4 |
Correct |
376 ms |
10692 KB |
Output is correct |
5 |
Correct |
118 ms |
6600 KB |
Output is correct |
6 |
Correct |
13 ms |
980 KB |
Output is correct |
7 |
Correct |
16 ms |
464 KB |
Output is correct |