This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int n, sz;
long long m, x;
cin >> n >> m;
vector < long long > a, b;
for(int i = 0; i < n; i++){
cin >> x;
if(i & 1){
a.push_back(x);
}
else{
b.push_back(x);
}
}
long long ans = 0;
sz = (int)a.size();
vector < long long > q;
for(int i = 1; i < (1 << sz); i++){
long long sum = 0;
for(int j = 0; j < sz; j++){
if((i >> j) & 1){
sum += a[j];
}
}
if(sum <= m){
ans += 1;
q.push_back(sum);
}
}
sort(q.begin(), q.end());
sz = (int)b.size();
for(int i = 1; i < (1 << sz); i++){
long long sum = 0;
for(int j = 0; j < sz; j++){
if((i >> j) & 1){
sum += b[j];
}
}
if(sum <= m){
ans += 1;
ans += upper_bound(q.begin(), q.end(), m - sum) - q.begin();
}
}
cout << ans + 1;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |