从代码量来讲真的是水题,只不过一开始交(sum+1)/2错了,以为要排除自己跟自己比赛的情况,没有那么简单。。。其实真的很简单,因为只有一个人的得分比其他所有人的得分加起来都多的时候,这个人才会自己跟自己比赛。
果然最近是被虐残了。
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
#define INF 1000000000
#define maxn 100005
#define rep(i,x,y) for(int i=x;i<=y;i++)
#define mset(x) memset(x,0,sizeof(x))
typedef __int64 ll;
int main(){
// freopen("a.txt","r",stdin);
// freopen(".out","w",stdout);
int kase,n,x;
cin>>kase;
rep(ks,1,kase){
cin>>n;
ll sum=0;
int maxx=0;
rep(i,1,n){
cin>>x;
sum+=x;
maxx = max(x,maxx);
}
printf("Case #%d: ",ks);
if( (sum+1)/2 > maxx ){
cout<<(sum+1)/2<<endl;
}
else{
cout<<maxx<<endl;
}
}
return 0;
}
/*
DESCRIPTION:
5
1 1 2 3 3 5
一开始想到答案是(sum+1)/2,但是有可能会出现自己和自己比赛的情况,
有这种情况的时候,一定是最大的值a[n]>(sum+1)/2,即a[n]>a[1]+...+a[n-1]
*/