-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUVA-11729.cpp
55 lines (48 loc) · 853 Bytes
/
UVA-11729.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/**
* UVA-11729
* 21/12/15 15:51:33
* xuchen
**/
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string.h>
#include <algorithm>
#include <stdlib.h>
#include <queue>
#include <stack>
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 1005;
struct solder{
int a, b;
};
bool cmp(solder i, solder j)
{
return i.a > j.a;
}
solder s[N];
int main()
{
int t, n, ans;
t = 0;
while(scanf("%d", &n) && n!=0)
{
t++;
for(int i=0; i<n; i++)
{
scanf("%d%d", &s[i].b, &s[i].a);
}
sort(s, s+n, cmp);
ans = 0;
int preb = 0;
for(int i=0; i<n; i++)
{
ans = max(ans, preb+s[i].a+s[i].b);
preb += s[i].b;
}
printf("Case %d: %d\n", t, ans);
}
return 0;
}