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;
typedef long long ll;
vector<ll> A, B;
int n;
ll m;
ll price_a[20], price_b[20];
int main(){
cin >> n >> m;
for(int i = 0; i < n/2; i++){
cin >> price_a[i];
}
for(int i = 0; i < (n+1)/2; i++){
cin >> price_b[i];
}
for(int b = 0; b < (1 << n/2); b++){
ll subset_sum = 0;
for(int i = 0; i < n/2; i++){
if(b >> i & 1){
subset_sum += price_a[i];
}
}
A.push_back(subset_sum);
}
for(int b = 0; b < (1 << (n+1)/2); b++){
ll subset_sum = 0;
for(int i = 0; i < (n+1)/2; i++){
if(b >> i & 1){
subset_sum += price_b[i];
}
}
B.push_back(subset_sum);
}
sort(A.begin(),A.end());
ll ans = 0;
for(ll &b : B){
ans += upper_bound(A.begin(),A.end(),m-b) - A.begin();
}
cout << ans << '\n';
}
# | 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... |