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;
#define int long long
vector<int>vec;
int a[50],n,m,ans;
void calcLeft(int i,int sum) {
if (i > n / 2) {
if (sum <= m) vec.push_back(sum);
return;
}
calcLeft(i + 1,sum);
calcLeft(i + 1,sum + a[i]);
}
int tknp(int l,int r,int x) {
int ans = 0;
while (l <= r) {
int mid = (l + r) / 2;
if (vec[mid] <= x) ans = max(ans,mid + 1),l = mid + 1;
else r = mid - 1;
}
return ans;
}
void calcRight(int i,int sum) {
if (i > n) {
if (sum <= m) ans += tknp(0,vec.size() - 1,m - sum);
return;
}
calcRight(i + 1,sum);
calcRight(i + 1,sum + a[i]);
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> a[i];
calcLeft(1,0);
sort(vec.begin(),vec.end());
calcRight(n / 2 + 1,0);
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... |