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>
#define ll long long
#define pii pair<int, int>
using namespace std;
const int N = 2e5+1;
int n;
ll m, a[N];
int main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin >> n >> m;
for (int i = 0; i < n; cin >> a[i++]);
vector<ll> sums;
for (int msk = 0; msk < (1 << (n/2)); msk++) {
ll sum = 0;
for (int i = 0; i < n/2; i++) {
if (msk>>i&1) {
sum += a[i];
}
}
sums.push_back(sum);
}
sort(sums.begin(), sums.end());
ll sol = 0;
for (int msk = 0; msk < (1 << (n/2 + n%2)); msk++) {
ll sum = 0;
for (int i = 0; i < n/2+n%2; i++) {
if (msk>>i&1) {
sum += a[n/2+n%2+i];
}
}
if (sum >= m) continue;
int idx = upper_bound(sums.begin(), sums.end(), m-sum)-sums.begin();
assert(sum + sums[idx - 1] <= m);
sol += idx;
}
cout << sol;
}
# | 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... |