#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
#define ld long double
// 217
// 44
using namespace std;
const int MAXN = 40;
ll a[MAXN], b[MAXN];
int main() {
//ifstream cin("A.in");
//ofstream cout("A.out");
int i, n;
ll m;
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n >> m;
int sz1 = (n + 1) / 2, sz2 = n / 2;
for(i = 0; i < sz1; i++) {
cin >> a[i];
}
vector <ll> sa;
for(int conf = 0; conf < (1 << sz1); conf++) {
ll cur = 0;
for(i = 0; i < sz1; i++) {
if(conf & (1 << i)) {
cur += a[i];
}
}
sa.push_back(cur);
}
sort(sa.begin(), sa.end());
for(i = 0; i < sz2; i++) {
cin >> b[i];
}
vector <ll> sb;
for(int conf = 0; conf < (1 << sz2); conf++) {
ll cur = 0;
for(i = 0; i < sz2; i++) {
if(conf & (1 << i)) {
cur += b[i];
}
}
sb.push_back(cur);
}
sort(sb.begin(), sb.end());
int pos = (1 << sz2) - 1;
ll ans = 0;
for(i = 0; i < (1 << sz1); i++) {
while(pos >= 0 && sa[i] + sb[pos] > m) {
pos--;
}
ans += pos + 1;
}
cout << ans;
//cin.close();
//cout.close();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
420 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
380 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
2540 KB |
Output is correct |
2 |
Correct |
79 ms |
5552 KB |
Output is correct |
3 |
Correct |
339 ms |
20984 KB |
Output is correct |
4 |
Correct |
79 ms |
5544 KB |
Output is correct |
5 |
Correct |
16 ms |
1648 KB |
Output is correct |
6 |
Correct |
11 ms |
1016 KB |
Output is correct |
7 |
Correct |
19 ms |
1776 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
2928 KB |
Output is correct |
2 |
Correct |
28 ms |
2412 KB |
Output is correct |
3 |
Correct |
139 ms |
10620 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
8 ms |
1020 KB |
Output is correct |
6 |
Correct |
18 ms |
1652 KB |
Output is correct |
7 |
Correct |
19 ms |
1652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
59 ms |
4416 KB |
Output is correct |
2 |
Correct |
117 ms |
8596 KB |
Output is correct |
3 |
Correct |
117 ms |
8672 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
85 ms |
8700 KB |
Output is correct |
6 |
Correct |
296 ms |
20948 KB |
Output is correct |
7 |
Correct |
117 ms |
8544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
250 ms |
16852 KB |
Output is correct |
2 |
Correct |
30 ms |
2412 KB |
Output is correct |
3 |
Correct |
10 ms |
1016 KB |
Output is correct |
4 |
Correct |
2 ms |
380 KB |
Output is correct |
5 |
Correct |
8 ms |
1016 KB |
Output is correct |
6 |
Correct |
242 ms |
16696 KB |
Output is correct |
7 |
Correct |
19 ms |
1648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
2416 KB |
Output is correct |
2 |
Correct |
77 ms |
5480 KB |
Output is correct |
3 |
Correct |
10 ms |
1016 KB |
Output is correct |
4 |
Correct |
10 ms |
1016 KB |
Output is correct |
5 |
Correct |
86 ms |
8540 KB |
Output is correct |
6 |
Correct |
27 ms |
2416 KB |
Output is correct |
7 |
Correct |
317 ms |
20948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
320 ms |
20952 KB |
Output is correct |
2 |
Correct |
29 ms |
2388 KB |
Output is correct |
3 |
Correct |
10 ms |
1016 KB |
Output is correct |
4 |
Correct |
345 ms |
20920 KB |
Output is correct |
5 |
Correct |
110 ms |
10592 KB |
Output is correct |
6 |
Correct |
19 ms |
1648 KB |
Output is correct |
7 |
Correct |
36 ms |
2928 KB |
Output is correct |