This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// author - alimammadzade
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
cin.tie(nullptr)->sync_with_stdio(false);
// system("cls"), freopen("in.txt", "r", stdin);
int n, m, res = 0;
cin >> n >> m;
vector<int> fi, se;
vector<int> fii, see;
for (int i = 0; i < n / 2; i++) {
int x;
cin >> x;
fi.push_back(x);
}
for (int i = n / 2; i < n; i++) {
int x;
cin >> x;
se.push_back(x);
}
int n1 = fi.size(), n2 = se.size();
for (int i = 0; i < (1 << n1); i++) {
int sum = 0;
for (int j = 0; j < n1; j++)
if (i & (1 << j)) sum += fi[j];
fii.push_back(sum);
}
for (int i = 0; i < (1 << n2); i++) {
int sum = 0;
for (int j = 0; j < n2; j++)
if (i & (1 << j)) sum += se[j];
see.push_back(sum);
}
sort(fii.begin(), fii.end());
sort(see.begin(), see.end());
for (int& i : fii) {
if (i > m) break;
res += upper_bound(see.begin(), see.end(), m - i) - see.begin();
}
cout << res;
}
# | 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... |