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;
typedef long long ll;
typedef long double ld;
ll niz[45];
ll niz1[5000005];
ll niz2[5000005];
int main(){
ios_base::sync_with_stdio(false);
cout.precision(10);
cout<<fixed;
int n;
ll m;
cin >> n >> m;
for(int i=1; i<=n; i++){
cin >> niz[i];
}
int k = n/2;
for(int i=0; i<(1<<k); i++){
for(int j=1; j<=k; j++){
if(i & (1 << (j-1))) niz1[i+1] += niz[j];
}
}
int p = n - k;
for(int i=0; i<(1<<p); i++){
for(int j=k+1; j<=n; j++){
if(i & (1 << (j-k-1))) niz2[i+1] += niz[j];
}
}
k = (1 << k);
p = (1 << p);
int tren = 0;
ll cnt = 0;
sort(niz1+1, niz1+1+k);
sort(niz2+1, niz2+1+p);
for(int i=k; i>=1; i--){
while(niz1[i] + niz2[tren+1] <= m && tren < p) tren++;
cnt += tren;
}
cout << cnt;
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... |