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 <iostream>
#include <vector>
#include <algorithm>
using namespace std;
long long tab[50];
vector<long long>w;
vector<long long>w2;
void calculate_values(int start,int ile,int id)
{
for(int i=0;i<(1<<ile);i++){
long long suma=0;
for(int j=0;j<ile;j++){
if((i&(1<<j))>0){
suma+=tab[start+j];
}
}
if(id==1){
w.push_back(suma);
}
else{
w2.push_back(suma);
}
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int ile;
long long limit;
cin>>ile>>limit;
for(int i=0;i<ile;i++){
cin>>tab[i];
}
if(ile==1){
if(tab[0]<=limit){
cout<<"2";
}
else{
cout<<"1";
}
return 0;
}
calculate_values(0,ile/2,1);
calculate_values(ile/2,ile-(ile/2),2);
sort(w.begin(),w.end());
sort(w2.begin(),w2.end());
long long war=0;
long long index=-1;
for(int i=(int)w.size()-1;i>=0;i--){
while(index+1<(int)w2.size()&&w2[index+1]+w[i]<=limit){
index++;
}
war+=(index+1);
}
cout<<war;
return 0;
}
# | 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... |