HDU 4974 A simple water problem
签到题,很容易贪心得到答案是(sum + 1) / 2和ai最大值的最大值
代码:
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int N = 100005; typedef long long ll; int t, n; ll a, Max, sum; int main() { int cas = 0; scanf("%d", &t); while (t--) { scanf("%d", &n); Max = 0; sum = 0; ll num = 0; for (int i = 0; i < n; i++) { scanf("%I64d", &num); Max = max(Max, num); sum += num; } sum = (sum + 1) / 2; printf("Case #%d: %I64d\n", ++cas, max(sum, Max)); } return 0; }
HDU 4974 A simple water problem(贪心),布布扣,bubuko.com
时间: 2024-10-25 21:40:18