hdu 4974 贪心

时间:2023-03-09 03:49:36
hdu 4974 贪心

http://acm.hdu.edu.cn/showproblem.php?pid=4974

n个人进行选秀,有一个人做裁判,每次有两人进行对决,裁判可以选择为两人打分,可以同时加上1分,或者单独为一个人加分,或者都不加。给出最后的比分情况,问说最少要比多少次才能获得现在的得分状态。

直接贪心模拟,或者推出结论为(sum + 1) / 2和ai最大值的最大值

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <queue>
#include <vector>
#include<map>
#include <iostream>
#include <algorithm>
using namespace std;
#define RD(x) scanf("%d",&x)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define clr0(x) memset(x,0,sizeof(x))
typedef long long LL;
int n;
int s[100005]; int main() {
int n,_;
RD(_);
for(int cas = 1;cas <= _;++cas){
printf("Case #%d: ",cas);
RD(n);
for(int i = 0;i < n;i++){
RD(s[i]);
}
LL ans = 0,cnt = 0;
sort(s,s+n);
for(int j = n-1;j>=0;--j){
if (cnt >= s[j])
cnt -= s[j];
else{
cnt = s[j] - cnt;
ans += cnt;
}
}
printf("%I64d\n",ans);
}
return 0;
}