#include "bits/stdc++.h"
#define F first
#define S second
#define ll long long
#define pii pair<ll,ll>
const ll mxN = 2e5 + 5;
const ll mod = 1e9 + 7;
using namespace std;
vector<ll>v;
ll a[50];
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n,m;
ll ans = 0;
cin >>n>>m;
for(ll i = 0;i < n;i++) cin >>a[i];
ll hf = n / 2,sf = (n + 1) / 2;
for(ll mask = 0;mask < (1 << hf);mask++){
ll sum = 0;
for(ll i = 0;i < hf;i++){
if((mask >> i) % 2){
sum += a[i];
if(sum > m) break;
}
}
if(sum > m) continue;
v.push_back(sum);
}
// cout<<'\n';
sort(v.begin(),v.end());
// for(auto x : v) cout<<x<<' ';
// cout<<'\n';
for(ll mask = 0;mask < (1 << sf);mask++){
ll sum = 0;
for(ll i = 0;i < sf;i++){
if((mask >> i) % 2){
sum += a[i + hf];
if(sum > m) break;
}
}
if(sum > m) continue;
ans += upper_bound(v.begin(),v.end(),m - sum) - v.begin();
// cout<<sum<<' '<<upper_bound(v.begin(),v.end(),m - sum) - v.begin()<<'\n';
}
cout<<ans;
}
# |
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 |
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 |
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 |
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 |
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 |
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 |
24 ms |
988 KB |
Output is correct |
2 |
Correct |
75 ms |
2520 KB |
Output is correct |
3 |
Correct |
324 ms |
9924 KB |
Output is correct |
4 |
Correct |
73 ms |
2516 KB |
Output is correct |
5 |
Correct |
11 ms |
988 KB |
Output is correct |
6 |
Correct |
6 ms |
736 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
1500 KB |
Output is correct |
2 |
Correct |
24 ms |
992 KB |
Output is correct |
3 |
Correct |
147 ms |
4780 KB |
Output is correct |
4 |
Correct |
0 ms |
600 KB |
Output is correct |
5 |
Correct |
4 ms |
736 KB |
Output is correct |
6 |
Correct |
11 ms |
992 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
1500 KB |
Output is correct |
2 |
Correct |
128 ms |
2520 KB |
Output is correct |
3 |
Correct |
114 ms |
2516 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
63 ms |
2532 KB |
Output is correct |
6 |
Correct |
182 ms |
9928 KB |
Output is correct |
7 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
254 ms |
5588 KB |
Output is correct |
2 |
Correct |
22 ms |
992 KB |
Output is correct |
3 |
Correct |
8 ms |
736 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
6 ms |
736 KB |
Output is correct |
6 |
Correct |
139 ms |
5072 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
992 KB |
Output is correct |
2 |
Correct |
74 ms |
2520 KB |
Output is correct |
3 |
Correct |
7 ms |
736 KB |
Output is correct |
4 |
Correct |
7 ms |
736 KB |
Output is correct |
5 |
Correct |
75 ms |
2592 KB |
Output is correct |
6 |
Correct |
16 ms |
988 KB |
Output is correct |
7 |
Correct |
5 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
305 ms |
10484 KB |
Output is correct |
2 |
Correct |
26 ms |
992 KB |
Output is correct |
3 |
Correct |
8 ms |
732 KB |
Output is correct |
4 |
Correct |
322 ms |
9908 KB |
Output is correct |
5 |
Correct |
92 ms |
4820 KB |
Output is correct |
6 |
Correct |
12 ms |
992 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |