#pragma GCC target ("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> pl;
#define K first
#define V second
#define G(x) ll x; cin >> x;
#define GD(x) ld x; cin >> x;
#define GS(s) string s; cin >> s;
#define EX(x) { cout << x << '\n'; exit(0); }
#define A(a) (a).begin(), (a).end()
#define F(i, l, r) for (ll i = (l); i < r; ++i)
#define NN
#define M 1000000007 // 998244353
int main(){
// freopen("a.in", "r", stdin);
// freopen("a.out", "w", stdout);
ios_base::sync_with_stdio(false); cin.tie(0);
cout << fixed << setprecision(20);
G(n) G(k)
vector<ll> v(n); for (auto &x: v) cin >> x;
if (n == 1){
cout << 1 + (v[0] <= k)* v[0] << '\n';
exit(0);
}
ll hlf = n/2;
vector<ll> th(1<<hlf);
F(bm, 0, 1<<(hlf)) {
ll s = 0;
F(i, 0, hlf) if ((1<<i)&bm) s += v[n-hlf+i];
th[bm] = s;
}
hlf = n-hlf;
vector<ll> th2(1<<hlf);
F(bm, 0, 1<<hlf) {
ll s = 0;
F(i, 0, hlf) if ((1<<i)&bm) s += v[i];
th2[bm] = s;
}
sort(A(th)); sort(A(th2));
ll rp = th2.size()-1;
ll ans = 0;
for (const auto &x: th) {
while (rp >= 0 and x + th2[rp] > k) --rp;
ans += rp+1;
}
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
456 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 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 |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
1884 KB |
Output is correct |
2 |
Correct |
43 ms |
4440 KB |
Output is correct |
3 |
Correct |
182 ms |
16728 KB |
Output is correct |
4 |
Correct |
44 ms |
4584 KB |
Output is correct |
5 |
Correct |
6 ms |
1372 KB |
Output is correct |
6 |
Correct |
4 ms |
856 KB |
Output is correct |
7 |
Correct |
10 ms |
1372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
2396 KB |
Output is correct |
2 |
Correct |
15 ms |
1884 KB |
Output is correct |
3 |
Correct |
65 ms |
8536 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
3 ms |
860 KB |
Output is correct |
6 |
Correct |
9 ms |
1500 KB |
Output is correct |
7 |
Correct |
9 ms |
1756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
3556 KB |
Output is correct |
2 |
Correct |
64 ms |
6608 KB |
Output is correct |
3 |
Correct |
63 ms |
6604 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
29 ms |
6492 KB |
Output is correct |
6 |
Correct |
137 ms |
16872 KB |
Output is correct |
7 |
Correct |
62 ms |
6492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
131 ms |
12764 KB |
Output is correct |
2 |
Correct |
15 ms |
1884 KB |
Output is correct |
3 |
Correct |
5 ms |
988 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
4 ms |
1148 KB |
Output is correct |
6 |
Correct |
141 ms |
12632 KB |
Output is correct |
7 |
Correct |
9 ms |
1368 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
2136 KB |
Output is correct |
2 |
Correct |
42 ms |
4444 KB |
Output is correct |
3 |
Correct |
5 ms |
856 KB |
Output is correct |
4 |
Correct |
5 ms |
856 KB |
Output is correct |
5 |
Correct |
37 ms |
6492 KB |
Output is correct |
6 |
Correct |
14 ms |
1880 KB |
Output is correct |
7 |
Correct |
166 ms |
16868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
174 ms |
16728 KB |
Output is correct |
2 |
Correct |
15 ms |
1880 KB |
Output is correct |
3 |
Correct |
5 ms |
856 KB |
Output is correct |
4 |
Correct |
182 ms |
16732 KB |
Output is correct |
5 |
Correct |
43 ms |
8740 KB |
Output is correct |
6 |
Correct |
9 ms |
1372 KB |
Output is correct |
7 |
Correct |
19 ms |
2528 KB |
Output is correct |