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;
int main() {
//freopen("in.txt", "r", stdin);
ios::sync_with_stdio(false);
cin.tie(0);
int n; ll m; cin >> n >> m;
ll a[n];
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
vector<ll> v;
int s = n/2;
for (int i = 0; i < (1<<s); ++i) {
ll cur = 0;
for (int j = 0; j < s; ++j) if (i & (1<<j)) cur += a[j];
v.push_back(cur);
}
sort(v.begin(), v.end());
ll ans = 0;
for (int i = 0; i < (1<<(n-s)); ++i) {
ll cur = 0;
for (int j = s; j < n; ++j) if (i & (1<<(j-s))) cur += a[j];
ll maxi = m - cur;
ans += upper_bound(v.begin(), v.end(), maxi) - v.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... |