#include "bits/stdc++.h"
using namespace std;
const int MAXN = 2e5 + 10;
const int MOD = 1e9 + 7;
#define int long long
mt19937_64 rng((int)std::chrono::steady_clock::now().time_since_epoch().count());
int rnd(int x, int y) {
int u = uniform_int_distribution<int>(x, y)(rng); return u;
}
int bm(int b, int p) {
if(p==0) return 1;
int r = bm(b, p/2);
if(p&1) return (((r*r) % MOD) * b) % MOD;
return (r*r) % MOD;
}
int inv(int b) {
return bm(b, MOD-2);
}
int f[MAXN];
int nCr(int n, int r) {
int ans = f[n]; ans *= inv(f[r]); ans %= MOD;
ans *= inv(f[n-r]); ans %= MOD; return ans;
}
void precomp() {
f[0] = 1;
for(int i=1; i<MAXN; i++) f[i] = (f[i-1] * i) % MOD;
}
void solve(int tc) {
int n, m;
cin >> n >> m;
vector<int> l, r;
for(int i=0; i<n/2; i++) {
int x;cin >> x;
l.push_back(x);
}
for(int i=0; i<n-n/2; i++) {
int x;cin >> x;
r.push_back(x);
}
vector<int> v;
int L = l.size();
for(int i=0; i<(1<<L); i++) {
int e = 0;
for(int j=0; j<L; j++) {
if(i & (1<<j)) {
e += l[j];
}
}
v.push_back(e);
}
sort(v.begin(), v.end());
int R = r.size();
int ans = 0;
for(int i=0; i<(1<<R); i++) {
int e = 0;
for(int j=0; j<R; j++) {
if(i & (1<<j)) {
e += r[j];
}
}
int lb = 0, rb = v.size() - 1;
while(lb < rb) {
int mid = (lb + rb + 1) >> 1;
if(v[mid] + e <= m) lb = mid;
else rb = mid - 1;
}
if(v[lb] + e <= m) ans += lb + 1;
}
cout << ans << "\n";
}
int32_t main(){
precomp();
ios::sync_with_stdio(0); cin.tie(0);
int t = 1; //cin >> t;
for(int i=1; i<=t; i++) solve(i);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1868 KB |
Output is correct |
2 |
Correct |
3 ms |
1876 KB |
Output is correct |
3 |
Correct |
3 ms |
1868 KB |
Output is correct |
4 |
Correct |
3 ms |
1868 KB |
Output is correct |
5 |
Correct |
2 ms |
1880 KB |
Output is correct |
6 |
Correct |
3 ms |
1868 KB |
Output is correct |
7 |
Correct |
3 ms |
1868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1868 KB |
Output is correct |
2 |
Correct |
2 ms |
1868 KB |
Output is correct |
3 |
Correct |
2 ms |
1880 KB |
Output is correct |
4 |
Correct |
3 ms |
1868 KB |
Output is correct |
5 |
Correct |
2 ms |
1868 KB |
Output is correct |
6 |
Correct |
3 ms |
1868 KB |
Output is correct |
7 |
Correct |
3 ms |
1868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1868 KB |
Output is correct |
2 |
Correct |
3 ms |
1868 KB |
Output is correct |
3 |
Correct |
3 ms |
1884 KB |
Output is correct |
4 |
Correct |
3 ms |
1868 KB |
Output is correct |
5 |
Correct |
4 ms |
1876 KB |
Output is correct |
6 |
Correct |
3 ms |
1868 KB |
Output is correct |
7 |
Correct |
3 ms |
1812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
2512 KB |
Output is correct |
2 |
Correct |
94 ms |
4040 KB |
Output is correct |
3 |
Correct |
439 ms |
10184 KB |
Output is correct |
4 |
Correct |
102 ms |
4040 KB |
Output is correct |
5 |
Correct |
19 ms |
2512 KB |
Output is correct |
6 |
Correct |
8 ms |
2264 KB |
Output is correct |
7 |
Correct |
15 ms |
2420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
3020 KB |
Output is correct |
2 |
Correct |
33 ms |
2528 KB |
Output is correct |
3 |
Correct |
181 ms |
6132 KB |
Output is correct |
4 |
Correct |
3 ms |
1880 KB |
Output is correct |
5 |
Correct |
9 ms |
2264 KB |
Output is correct |
6 |
Correct |
15 ms |
2512 KB |
Output is correct |
7 |
Correct |
15 ms |
2512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
68 ms |
2964 KB |
Output is correct |
2 |
Correct |
151 ms |
4052 KB |
Output is correct |
3 |
Correct |
147 ms |
4040 KB |
Output is correct |
4 |
Correct |
2 ms |
1868 KB |
Output is correct |
5 |
Correct |
88 ms |
3980 KB |
Output is correct |
6 |
Correct |
225 ms |
10152 KB |
Output is correct |
7 |
Correct |
91 ms |
4040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
327 ms |
6112 KB |
Output is correct |
2 |
Correct |
30 ms |
2512 KB |
Output is correct |
3 |
Correct |
12 ms |
2256 KB |
Output is correct |
4 |
Correct |
3 ms |
1868 KB |
Output is correct |
5 |
Correct |
10 ms |
2256 KB |
Output is correct |
6 |
Correct |
162 ms |
6012 KB |
Output is correct |
7 |
Correct |
15 ms |
2512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
2528 KB |
Output is correct |
2 |
Correct |
87 ms |
4032 KB |
Output is correct |
3 |
Correct |
11 ms |
2256 KB |
Output is correct |
4 |
Correct |
12 ms |
2260 KB |
Output is correct |
5 |
Correct |
114 ms |
4040 KB |
Output is correct |
6 |
Correct |
20 ms |
2516 KB |
Output is correct |
7 |
Correct |
252 ms |
10236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
409 ms |
10172 KB |
Output is correct |
2 |
Correct |
38 ms |
2524 KB |
Output is correct |
3 |
Correct |
11 ms |
2256 KB |
Output is correct |
4 |
Correct |
500 ms |
10164 KB |
Output is correct |
5 |
Correct |
130 ms |
6084 KB |
Output is correct |
6 |
Correct |
15 ms |
2512 KB |
Output is correct |
7 |
Correct |
33 ms |
3020 KB |
Output is correct |