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 ll long long
#define ld long long+
int main(){
ll n, m, n1, n2;
cin>>n>>m;
n1 = n / 2;
n2 = n - n1;
vector<ll> v1(n1, 0), v2(n2, 0);
for (int i = 0; i < n1; i++){
cin>>v1[i];
}
for (int i = 0; i < n2; i++){
cin>>v2[i];
}
vector<ll> ar1, ar2;
for (int i = 0; i < (1<<n1); i++){
ll su = 0;
for (int j = 0; j < n1; j++){
int val = i & (1<<j);
if (val != 0){
su += v1[j];
}
}
if (su <= m){
ar1.push_back(su);
}
}
for (int i = 0; i < (1<<n2); i++){
ll su = 0;
for (int j = 0; j < n2; j++){
int val = i & (1<<j);
if (val != 0){
su += v2[j];
}
}
if (su <= m){
ar2.push_back(su);
}
}
sort(ar1.begin(), ar1.end());
sort(ar2.begin(), ar2.end());
ll ans = 0;
for (auto el : ar1){
ll res = upper_bound(ar2.begin(), ar2.end(), m - el) - ar2.begin();
ans += res;
}
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... |