BTime
limit:1000MS
Memory Limit:0KB
64bit IO Format:%lld &%llu SubmitStatus
Description
Perhaps everyone has a dream of becoming a general, and so is the small. From childhood, small-time determined to grow up to be a soldier, defend. One day, he had a dream, in the dream, he is a wise Shenwu general, but the enemy will soon invade, as the general of his duty to stand up, so he began to do some strategic deployment. Assuming that the current small light has n subordinates, each of the subordinates needs to complete a task. I need a small small bi minute to explain the task, and then he will immediately independent, uninterrupted execution Ji minutes after the completion of the task. The small aperture needs to select the order of the task, so that all tasks are executed as soon as possible (that is, the last completed task should be completed as soon as possible). Note that it is not possible to account for two subordinates at the same time, but the subordinates can perform their respective tasks at the same time.
Input
Input contains multiple sets of data, the first behavior of each group of data under the number of N (1<=n<=1000), the following n rows, two positive integers per line B and J (1<=b<=10000,1<=j<=10000), That is, the time of the task and the time the task was executed. The input end flag is n=0.
Output
For each group of data for the group, output the shortest time for all tasks to complete. The specific output format is shown in the sample, beginning with case, after case output the current data ordinal, and then output the answer.
Sample Input
32 53 22 133 34 4 5 50
Sample Output
Case 1:8case 2:15
#include <iostream>#include<stdio.h>#include<algorithm>using namespacestd;structnode{intB,j;} wor[1005];BOOLCMP (Node w1,node W2) {returnW1.j>W2.J;}intMain () {intN; intt=1; while((scanf ("%d", &n)) &&n!=0){ for(intI=0; i<n;i++) {scanf ("%d%d",&wor[i].b,&WOR[I].J); } sort (Wor,wor+n,cmp); inttmp=0; intans=0; for(intI=0; i<n;i++) {tmp+=wor[i].b; Ans=max (tmp+Wor[i].j,ans); } printf ("Case %d:%d\n", t++, ans); } return 0;}
View Code
UVA 11729 Commando War