uva11729

来源:互联网 发布:薛冰是怎么死的 知乎 编辑:程序博客网 时间:2024/06/07 02:34

uva 11729

任务执行时间长的先交代

#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<iostream>#include<algorithm>using namespace std;#define MAXN (1000+5)struct node{    int b, j;        bool operator <(const node &a)const{         return j > a.j;    }};node per[MAXN];int main(){    int n, T = 0;    while(scanf("%d", &n) && n){        for(int i = 1; i <= n; i++) scanf("%d%d", &per[i].b, &per[i].j);        sort(per+1, per+n+1);                int ans = 0, now = 0;        ans = per[1].b + per[1].j;        now = per[1].b;                for(int i = 2; i <= n; i++){            now += per[i].b;            int add = now + per[i].j;            if(add > ans) ans = add;        }                printf("Case %d: %d\n", ++T, ans);    }        return 0;}


0 0