Topic Portal
1 /*2 greedy: Sort by precedence over long execution times3 */4#include <cstdio>5#include <algorithm>6#include <iostream>7#include <cstring>8#include <string>9#include <cmath>Ten using namespacestd; One A Const intMAXN = 1e3 +Ten; - Const intINF =0x3f3f3f3f; - structNode { the intb, J; - BOOL operator< (ConstNode &r)Const { - returnJ >R.J; - } + }NODE[MAXN]; - + intMainvoid)//UVA 11729 Commando War A { at //freopen ("uva_11729.in", "R", stdin); - - intNintCAS =0; - while(SCANF ("%d", &n) = =1&&N) - { - for(intI=1; i<=n; ++i) in { -scanf ("%d%d", &NODE[I].B, &NODE[I].J); to } + -Sort (node+1, node+1+n); the * intAns =0;intMX =-1; $ for(intI=1; i<=n; ++i)Panax Notoginseng { -Ans + =node[i].b; themx = max (mx, ans +NODE[I].J); + } A theprintf ("Case %d:%d\n", ++cas, MX); + } - $ return 0; $ } - - the /* - Case 1:8Wuyi Case 2:15 the */
Greedy UVA 11729 Commando War