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;
int n;
long long M;
long long a[44];
long long ans;
vector< long long > v1, v2;
void bt(int pos, int lim, long long sum, vector<long long> &v) {
if (pos == lim) {
v.push_back(sum); return;
}
bt(pos + 1, lim, sum, v);
bt(pos + 1, lim, sum + a[pos], v);
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n >> M;
for (int i = 0; i < n; ++i) cin >> a[i];
bt(0, n / 2, 0, v1);
bt(n / 2, n, 0, v2);
sort(v1.begin(), v1.end());
sort(v2.begin(), v2.end());
int ptr = v2.size() - 1;
for (int i = 0; i < v1.size(); ++i) {
if (v1[i] > M) break;
while(ptr >= 0 && v2[ptr] > M - v1[i]) --ptr;
// [0...ptr]
ans += ptr + 1;
}
printf("%lld\n", ans);
}
Compilation message (stderr)
bobek.cpp: In function 'int main()':
bobek.cpp:29:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < v1.size(); ++i) {
^
# | 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... |