#include <bits/stdc++.h>
using namespace std;
int N;
long long M;
vector<long long> nums;
vector<long long> half;
int main() {
ios_base::sync_with_stdio(false);
// freopen("1.in", "r", stdin);
cin >> N >> M;
nums.assign(N, 0);
for (int i = 0; i < N; i++)
cin >> nums[i];
for (int i = 0; i < (1 << (N / 2)); i++) {
long long sum = 0;
for (int j = 0; j < N / 2; j++)
if (i & (1 << j))
sum += nums[j];
half.push_back(sum);
}
sort(half.begin(), half.end());
long long res = 0;
for (int i = 0; i < (1 << (N - N / 2)); i++) {
long long sum = 0;
for (int j = N / 2; j < N; j++)
if (i & (1 << (j - N / 2)))
sum += nums[j];
int lo = 0, hi = half.size() - 1, ans = -1;
while (lo <= hi) {
int m = (lo + hi) / 2;
if (half[m] > M - sum)
hi = m - 1;
else
lo = m + 1, ans = m;
}
res += ans + 1;
}
cout << res << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
1024 KB |
Output is correct |
2 |
Correct |
114 ms |
2500 KB |
Output is correct |
3 |
Correct |
623 ms |
8704 KB |
Output is correct |
4 |
Correct |
120 ms |
2552 KB |
Output is correct |
5 |
Correct |
20 ms |
1024 KB |
Output is correct |
6 |
Correct |
9 ms |
768 KB |
Output is correct |
7 |
Correct |
18 ms |
1024 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
53 ms |
1504 KB |
Output is correct |
2 |
Correct |
43 ms |
1024 KB |
Output is correct |
3 |
Correct |
228 ms |
4716 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
11 ms |
768 KB |
Output is correct |
6 |
Correct |
18 ms |
1024 KB |
Output is correct |
7 |
Correct |
16 ms |
1024 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
79 ms |
1532 KB |
Output is correct |
2 |
Correct |
207 ms |
2552 KB |
Output is correct |
3 |
Correct |
204 ms |
2552 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
100 ms |
2552 KB |
Output is correct |
6 |
Correct |
281 ms |
8676 KB |
Output is correct |
7 |
Correct |
94 ms |
2680 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
451 ms |
4584 KB |
Output is correct |
2 |
Correct |
31 ms |
1024 KB |
Output is correct |
3 |
Correct |
12 ms |
768 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
11 ms |
768 KB |
Output is correct |
6 |
Correct |
202 ms |
4588 KB |
Output is correct |
7 |
Correct |
17 ms |
1024 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
1024 KB |
Output is correct |
2 |
Correct |
105 ms |
2552 KB |
Output is correct |
3 |
Correct |
12 ms |
768 KB |
Output is correct |
4 |
Correct |
12 ms |
768 KB |
Output is correct |
5 |
Correct |
118 ms |
2552 KB |
Output is correct |
6 |
Correct |
25 ms |
1024 KB |
Output is correct |
7 |
Correct |
279 ms |
8680 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
446 ms |
8672 KB |
Output is correct |
2 |
Correct |
37 ms |
1024 KB |
Output is correct |
3 |
Correct |
13 ms |
768 KB |
Output is correct |
4 |
Correct |
651 ms |
8816 KB |
Output is correct |
5 |
Correct |
132 ms |
4588 KB |
Output is correct |
6 |
Correct |
18 ms |
1024 KB |
Output is correct |
7 |
Correct |
38 ms |
1532 KB |
Output is correct |