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;
using ll = long long;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
ll m;
cin >> n >> m;
vector<ll> l, r;
for(int i = 0; i < n; i++) {
ll x;
cin >> x;
if (i > n/2) {
r.push_back(x);
} else {
l.push_back(x);
}
}
vector<ll> ls, rs;
const int ln = l.size(), rn = r.size();
for(int mask = 0; mask < (1 << ln); mask++) {
ll sum = 0;
for(int i = 0; i < ln; i++) {
if (mask & (1 << i)) {
sum += l[i];
}
}
ls.push_back(sum);
}
for(int mask = 0; mask < (1 << rn); mask++) {
ll sum = 0;
for(int i = 0; i < rn; i++) {
if (mask & (1 << i)) {
sum += r[i];
}
}
rs.push_back(sum);
}
ll ans = 0;
sort(ls.begin(), ls.end());
sort(rs.begin(), rs.end());
for(ll i : ls) {
ll idx = upper_bound(rs.begin(), rs.end(), m - i) - rs.begin();
ans += idx;
}
cout << ans << "\n";
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... |