#include <bits/stdc++.h>
#define N 45
using namespace std;
long long arr[N];
vector<long long> v;
void solve(){
long long n,m;
cin >> n >> m;
for(int i=0;i<n;i++)cin >> arr[i];
long long ans = 0;
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 += arr[j];
}
}
v.push_back(sum);
}
sort(v.begin(),v.end());
int c = n/2;
n -= n/2;
for(int i=0;i<(1<<n);i++){
long long sum = 0;
for(int j=0;j<n;j++){
if(i & ( 1<<j)){
sum += arr[c+j];
}
}
if(sum <=m){
ans += upper_bound(v.begin(),v.end(),m-sum) -v.begin();
}
}
cout << ans;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#ifdef Local
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int t=1;
//cin>>t;
while(t--){
solve();
}
#ifdef Local
cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
#endif
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
1008 KB |
Output is correct |
2 |
Correct |
103 ms |
2536 KB |
Output is correct |
3 |
Correct |
549 ms |
8800 KB |
Output is correct |
4 |
Correct |
107 ms |
2556 KB |
Output is correct |
5 |
Correct |
17 ms |
1008 KB |
Output is correct |
6 |
Correct |
8 ms |
752 KB |
Output is correct |
7 |
Correct |
14 ms |
1008 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
52 ms |
1516 KB |
Output is correct |
2 |
Correct |
37 ms |
1008 KB |
Output is correct |
3 |
Correct |
206 ms |
4588 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
8 ms |
752 KB |
Output is correct |
6 |
Correct |
16 ms |
1008 KB |
Output is correct |
7 |
Correct |
15 ms |
1008 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
81 ms |
1516 KB |
Output is correct |
2 |
Correct |
170 ms |
2536 KB |
Output is correct |
3 |
Correct |
177 ms |
2536 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
95 ms |
2536 KB |
Output is correct |
6 |
Correct |
248 ms |
8672 KB |
Output is correct |
7 |
Correct |
76 ms |
2536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
380 ms |
4580 KB |
Output is correct |
2 |
Correct |
31 ms |
1008 KB |
Output is correct |
3 |
Correct |
11 ms |
752 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
9 ms |
752 KB |
Output is correct |
6 |
Correct |
196 ms |
4580 KB |
Output is correct |
7 |
Correct |
14 ms |
1008 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
1008 KB |
Output is correct |
2 |
Correct |
99 ms |
2536 KB |
Output is correct |
3 |
Correct |
10 ms |
752 KB |
Output is correct |
4 |
Correct |
11 ms |
752 KB |
Output is correct |
5 |
Correct |
121 ms |
2536 KB |
Output is correct |
6 |
Correct |
25 ms |
1008 KB |
Output is correct |
7 |
Correct |
234 ms |
8668 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
415 ms |
8672 KB |
Output is correct |
2 |
Correct |
36 ms |
1156 KB |
Output is correct |
3 |
Correct |
11 ms |
900 KB |
Output is correct |
4 |
Correct |
550 ms |
8668 KB |
Output is correct |
5 |
Correct |
139 ms |
4720 KB |
Output is correct |
6 |
Correct |
16 ms |
1008 KB |
Output is correct |
7 |
Correct |
27 ms |
1516 KB |
Output is correct |