"Title translation":
Problem analysis: Because tasks can be executed in parallel, it is intuitively a task that takes a long time to prioritize deployment. But this to the topic also gives you the task of time, so easy to let people think more.
There are only two possible cases for tasks x and Y, regardless of the time it takes to account for the task. X ends before y, and x ends after Y. Here it is discussed that X is done before Y.
When x and Y positions are not swapped, the completion time is: B[x] + b[y] + j[y]
After swapping H and Y positions, the completion time is: B[y] + b[x] + j[x]
If J[y] is greater than j[x], then the time is shortened after the interchange, so y should be executed before X. The other situation is similar.
This proves that the greedy strategy can be boldly used in the future.
#include <Cstdio>
#include <cstring>
#include <algorithm>
using namespace Std;
struct people
{
int b,j;
} p[1005];
int CMP (People a,people B)
{
Return a.j>b.j;
}
int main ()
{
int n,cas=0;
while (scanf ("%d", &n)!=eof&&n)
{
cas++;
for (int i=0; i<n; i++)
scanf ("%d%d", &P[I].B,&P[I].J);
Sort (p,p+n,cmp);
int sum=0,ans=0;
for (int i=0; i<n; i++)
{
sum+=p[i].b;
Ans=max (ANS,SUM+P[I].J);
}
printf ("Case%d:%d\n", Cas,ans);
}
return 0;
}
UVa 11729-commando War