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>
#pragma GCC optimize("unroll-loops,no-stack-protector,Ofast")
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll N=(1LL<<20)+1;
const ll MOD=1e9+7;
const ll INF=(1LL<<61);
const ld pi=acos(-1);
#define REP(i,n) for(int i=0;i<n;++i)
#define REP1(i,n) for(int i=1;i<=n;++i)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define lwb lower_bound
#define SZ(_a) (ll)_a.size()
#define count(_a) (ll)__builtin_popcount(_a)
ll num,k,n,m,ans,id,a[N],b[N];
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
cin>>num>>k;
n=num/2,m=num-n;
REP(i,n)cin>>a[1<<i];
REP(i,m)cin>>b[1<<i];
for(int i=0;i<(1<<n);i++){
a[i]=a[i^(i&-i)]+a[(i&-i)];
}
for(int i=0;i<(1<<m);i++){
b[i]=b[i^(i&-i)]+b[(i&-i)];
}
n=(1<<n),m=(1<<m);
sort(a,a+n,greater<ll> ());
sort(b,b+m);
REP(i,n){
while(id<m&&b[id]+a[i]<=k)++id;
ans+=id;
}
cout<<ans<<"\n";
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... |