比赛 |
20160420s |
评测结果 |
AAAAAATTTT |
题目名称 |
买汽水 |
最终得分 |
60 |
用户昵称 |
lxtgogogo |
运行时间 |
4.483 s |
代码语言 |
C++ |
内存使用 |
0.32 MiB |
提交时间 |
2016-04-20 10:58:34 |
显示代码纯文本
/*
Language: c++
Author: lxtgogogo
Date: 2016.04.20
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<ctime>
using namespace std;
inline int orz(){
int x=0;bool f=true;char ch=getchar();
while(ch>'9' || ch<'0') {if(ch=='-'){f=false;}ch=getchar();}
while(ch>='0' && ch<='9') {x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
return f?x:-x;
}
const int satoshi=42;
int n=0,m=0,ans=0;
int mengmengda[satoshi]={};
int sum[satoshi]={};
int sig=0;
bool srosatoshi(int a,int b){return a>b;}
void init(){
n=orz();m=orz();
for(int i=1;i<=n;i++) mengmengda[i]=orz();
sort(mengmengda+1,mengmengda+n+1,srosatoshi);
for(int i=n;i>=1;i--) sum[i]=mengmengda[i]+sum[i+1];
}
void cut_satoshi(int which,int hahaha){
if(hahaha>m) return ;
sig++;
if(sig>90000000) return ;
if(which==n+1)
{
if(hahaha>ans) ans=hahaha;
return ;
}
if(hahaha+sum[which]<ans) return ;
cut_satoshi(which+1,hahaha+mengmengda[which]);
cut_satoshi(which+1,hahaha);
}
int main(){
freopen("drink.in","r",stdin);
freopen("drink.out","w",stdout);
init();
cut_satoshi(1,0);
printf("%d\n",ans);
fclose(stdin);fclose(stdout);
return 0;
}