Commando War

临项交换.

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <set>
using namespace std;
#define reg register

int n, ans, sum, Case, mx;
struct date {
    int pre, ned;
}dt[10005];
bool cmp(date A, date B) {
    int mx1 = 0, mx2 = 0;
    mx1 = max(A.pre + A.ned, A.pre + B.pre + B.ned);
    mx2 = max(B.pre + B.ned, B.pre + A.pre + A.ned);
    return mx1 < mx2;
}
 
int main()
{
    while(1) {
        scanf("%d", &n);
        if (!n) return 0;
        Case++;
        ans = 0, sum = 0;
        for (reg int i = 1 ; i <= n ; i ++) scanf("%d%d", &dt[i].pre, &dt[i].ned);
        sort(dt + 1, dt + 1 + n, cmp);
        int hz = 0, mx = 0;
        for (reg int i = 1 ; i <= n ; i ++) {
            mx = max(mx, hz + dt[i].pre + dt[i].ned);
            hz += dt[i].pre; 
        }
        printf("Case %d: %d\n", Case, mx);
    }
    return 0;
}
/*
3
2 5
3 2
2 1
3
3 3
4 4
5 5
0
*/

 

posted @ 2020-09-27 10:58  zZhBr  阅读(160)  评论(0编辑  收藏  举报