hdu 4070 福州赛区网络赛J 贪心 ***
优先发路程最长的
1 #include<cstdio> 2 #include<iostream> 3 #include<algorithm> 4 #include<cstring> 5 #include<cmath> 6 #include<queue> 7 #include<map> 8 using namespace std; 9 #define MOD 1000000007 10 const int INF=0x3f3f3f3f; 11 const double eps=1e-5; 12 typedef long long ll; 13 #define cl(a) memset(a,0,sizeof(a)) 14 #define ts printf("*****\n"); 15 const int MAXN=100500; 16 int n,m,tt; 17 struct Node 18 { 19 int num,t; 20 }node[MAXN]; 21 bool cmp(Node a,Node b) 22 { 23 return a.t>b.t; 24 } 25 int main() 26 { 27 int i,j,k,ca=1; 28 #ifndef ONLINE_JUDGE 29 freopen("1.in","r",stdin); 30 #endif 31 scanf("%d",&tt); 32 while(tt--) 33 { 34 printf("Case %d: ",ca++); 35 scanf("%d",&n); 36 for(i=0;i<n;i++) 37 scanf("%d%d",&node[i].num,&node[i].t); 38 sort(node,node+n,cmp); 39 int sum=0; 40 int Max=0; 41 int tot=0; 42 for(i=0;i<n;i++) 43 { 44 sum=node[i].num+node[i].t-1+tot; 45 Max=max(sum,Max); 46 tot+=node[i].num; 47 48 } 49 printf("%d\n",Max+1); 50 } 51 }