记录编号 99836 评测结果 AAAAA
题目名称 [UVa 11729] 突击战 最终得分 100
用户昵称 GravatarOI永别 是否通过 通过
代码语言 C++ 运行时间 0.107 s
提交时间 2014-05-01 16:17:36 内存使用 0.31 MiB
显示代码纯文本
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
#define fi first
#define se second
#define pa pair <int, int>
int cases = 0;
vector <pa> a;
bool comp(const pa & a,const pa & b){
	return (a.se > b.se || (a.fi < b.fi && a.se == b.se));
}
int n;

inline int getint(){
	char ch;
	int x = 0;
	while (!isdigit(ch = getchar()));
	x = ch - 48;
	while (isdigit(ch = getchar())) x = x * 10 + ch - 48;
	return x;
}

int main(){
	freopen("commando.in","r",stdin);
	freopen("commando.out","w",stdout);
	while (n = getint(),n){
		printf("Case %d: ",++cases);
		a.clear();
		int x,y;
		int ans = 0;
		
		for (int i = 1; i <= n; i++){
			x = getint(); y = getint();
			a.push_back(make_pair(x,y));
			ans += x;
		}
		sort(a.begin(),a.end(),comp);
		int s = 0;
		for (int i = 0; i < n; i++){
			s += a.at(i).fi;
			ans = max(ans,s + a.at(i).se);
		}
		printf("%d\n",ans);
	}
	return 0;
}