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>
#define sf scanf
#define pf printf
#define rep(i,x,y) for(int i=x;i<=(y);i++)
#define drep(i,x,y) for(int i=x;i>=(y);i--)
#define ll long long
#define pb push_back
#define lb long double
using namespace std;
inline ll in(){ ll x=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9') (ch=='-'?f=-1:1),ch=getchar(); while(ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+ch-'0',ch=getchar(); return x*f; }
int n;
ll m,w[45],cnt,ans,p[1100000];
int main(){
n=in(); m=in();
rep(i,1,n) w[i]=in();
sort(w+1,w+1+n);
if(n==1){
pf("%lld\n",(m>=w[1]?1:0));
return 0;
}
int s=n/2-1;
rep(i,0,(1<<s)-1){
ll v=0;
rep(j,0,s-1){
if((i>>j)&1) v+=w[j+1];
if(v>m) break;
}
if(v>m) continue;
p[++cnt]=v;
}
sort(p+1,p+1+cnt);
s=n-s;
rep(i,0,(1<<s)-1){
ll v=0;
rep(j,0,s-1){
if((i>>j)&1) v+=w[j+n/2];
if(v>m) break;
}
if(v>m) continue;
int d=lower_bound(p+1,p+1+cnt,m-v)-p;
if(d>cnt) --d;
// cout<<d<<' '<<p[d]<<" "<<v<<"\n";
ans+=d;
}
pf("%lld\n",ans);
return 0;
}
Compilation message (stderr)
bobek.cpp: In function 'int main()':
bobek.cpp:19:10: warning: format '%lld' expects argument of type 'long long int', but argument 2 has type 'int' [-Wformat=]
19 | pf("%lld\n",(m>=w[1]?1:0));
| ~~~^ ~~~~~~~~~~~~~
| | |
| | int
| long long int
| %d
# | 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... |