比赛 |
20160420s |
评测结果 |
AAAAAAAAAA |
题目名称 |
买汽水 |
最终得分 |
100 |
用户昵称 |
咸鱼二号 |
运行时间 |
0.006 s |
代码语言 |
C++ |
内存使用 |
0.31 MiB |
提交时间 |
2016-04-20 09:53:45 |
显示代码纯文本
#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cmath>
#include<utility>
#include<cstdlib>
#include<iomanip> //cout<<setiosflags(ios::fixed)<<setprecision(2);
#include<ctime> //double a=(double)clock(); cout<<a<<endl;
#include<vector>
#include<queue>
using namespace std;
inline int read(){
int x=0,ff=1;char ch=getchar();
while(ch>'9'||ch<'0'){if(ch=='-')ff=-1; ch=getchar();}
while(ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=getchar();}
return ff*x;
}
inline int mymin(int xx,int yy)
{if(xx>yy)return yy;return xx;}
inline int mymax(int xx,int yy)
{if(xx<yy)return yy;return xx;}
inline bool mycmp(const int &xx,const int &yy)
{return xx>yy;}
int N,M,a[41],ans=0;
long long sum[41];
void dfs(int depth,int v){
if(clock()>950){
printf("%d\n",ans);
exit(0);
}
if(ans==M){
printf("%d\n",ans);
exit(0);
}
if(depth==N+1){
if(v>ans)
ans=v;
return;
}
if(v+sum[N]-sum[depth-1]<=ans)
return;
if(v+a[depth]<=M)
dfs(depth+1,v+a[depth]);
dfs(depth+1,v);
}
int main(){
freopen("drink.in","r",stdin);
freopen("drink.out","w",stdout);
N=read(),M=read();
for(int i=1;i<=N;i++)
a[i]=read(),sum[i]=a[i]+sum[i-1];
sort(a+1,a+1+N,mycmp);
for(int i=1;i<=N;i++)
if(ans+a[i]<=M)
ans+=a[i];
if(ans==sum[N]){
printf("%d\n",ans);
return 0;
}
dfs(1,0);
printf("%d\n",ans);
return 0;
}