This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//https://oj.uz/problem/view/CEOI15_bobek
#include<bits/stdc++.h>
using namespace std;
vector <long long> mv[2];
int n;
long long m, ans, a[50];
void backtrack(vector <long long> & mv, int i, int n, long long sum){
if (i == n+1){
mv.push_back(sum);
return;
}
backtrack(mv, i+1, n, sum);
backtrack(mv, i+1, n, sum+a[i]);
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> a[i];
backtrack(mv[0], 1, n/2, 0);
backtrack(mv[1], n/2+1, n, 0);
sort(mv[0].begin(), mv[0].end());
sort(mv[1].begin(), mv[1].end());
int cnt = mv[1].size()-1;
for (auto x : mv[0]){
while (cnt >= 0 && mv[1][cnt] + x > m) cnt--;
ans += cnt+1;
}
cout << ans;
}
# | 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... |