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;
void putStaff(vector <long long> v, vector <long long> &x) {
int n = v.size();
for(int i = 0; i < (1 << n); i++) {
long long sum = 0;
for(int j = 0; j < n; j++) {
if((i >> j) & 1) {
sum += v[j];
}
}
x.push_back(sum);
}
sort(x.begin(), x.end());
}
int main(int argc, char const *argv[])
{
int n;
long long budget;
cin >> n >> budget;
long long *a = new long long [n];
for(int i = 0; i < n; i++) {
cin >> a[i];
}
int half = n >> 1;
vector <long long> p1, p2;
vector <long long> sum1, sum2;
for(int i = 0; i < n; i++) {
if(i < half) p1.push_back(a[i]);
else p2.push_back(a[i]);
}
delete a;
putStaff(p1, sum1);
putStaff(p2, sum2);
long long ans = 0;
for(auto i : sum1) {
ans += upper_bound(sum2.begin(), sum2.end(), budget - i) - sum2.begin();
}
cout << ans << endl;
return 0;
}
# | 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... |