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>sum1, sum2;
int n, x;
int a[41];
void f1(int i, int sum){
if(i==n/2){
sum1.push_back(sum);
return;
}
f1(i+1, sum+a[i]);
f1(i+1, sum);
}
void f2(int i, int sum){
if(i==n){
sum2.push_back(sum);
return;
}
f2(i+1, sum+a[i]);
f2(i+1, sum);
}
signed main() {
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
cin >> n >> x;
for(int i = 0;i < n; i++)cin >> a[i];
f1(0, 0);
f2(n/2, 0);
sort(sum2.begin(), sum2.end());
int ans = 0;
for(auto i : sum1){
int idx = (upper_bound(sum2.begin(), sum2.end(), x-i) - sum2.begin());
auto it = upper_bound(sum2.begin(), sum2.end(), x-i);
ans += idx ;
}
cout << endl;
for(auto i : sum2)cout << i << " ";
cout << ans << endl;
}
Compilation message (stderr)
bobek.cpp: In function 'int main()':
bobek.cpp:36:10: warning: variable 'it' set but not used [-Wunused-but-set-variable]
36 | auto it = upper_bound(sum2.begin(), sum2.end(), x-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... |