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 lint = long long;
const int MAX_N = 40 + 2;
int n;
lint m;
lint c[MAX_N];
void solve_edge() {
if (n != 1) return;
lint ans = 1 + (bool) (c[1] <= m);
cout << ans << '\n';
}
int size1, size2;
vector<lint> ord_costs;
void precomp() {
size1 = n / 2;
size2 = n - n / 2;
for (int mask = 0; mask < (1 << size2); mask++) {
lint cost = 0;
for (int b = 0; b < size2; b++) {
if (!(mask & (1 << b))) continue;
cost += c[n / 2 + 1 + b];
}
ord_costs.push_back(cost);
}
sort(ord_costs.begin(), ord_costs.end());
}
int main() {
// freopen("ice.in", "r", stdin);
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> c[i];
solve_edge();
precomp();
lint ans = 0;
for (int mask = 0; mask < (1 << size1); mask++) {
lint cost = 0;
for (int b = 0; b < size1; b++) {
if (!(mask & (1 << b))) continue;
cost += c[1 + b];
}
lint tar_cost = m - cost;
lint tar_ind = upper_bound(ord_costs.begin(), ord_costs.end(), tar_cost) - ord_costs.begin();
ans += tar_ind;
}
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... |