Test instructions: There are n subordinates, confessed each of his subordinates to complete his corresponding tasks need bi time, and then complete the task requires Ji time,
Choose the order of the tasks, make the total time to spend the least
Because in any case, the time required to confess the N*BI is to be spent,
Then let the person who completes the task take a long time to do first, will j in descending order, update each person's task to complete the time spent
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <stack>6#include <vector>7#include <map>8#include <Set>9#include <queue>Ten#include <algorithm> One using namespacestd; A -typedefLong LongLL; - Const intINF = (1<< -)-1; the Const intMod=1000000007; - Const intmaxn=10005; - - intN; + structnode{ - intb,q; + } A[MAXN]; A at intCMP (node N1,node n2) { - returnN1.Q >n2.q; - } - - intMain () { - intKase =0; in while(SCANF ("%d", &n)! = EOF &&N) { - for(intI=1; i<=n;i++) scanf ("%d%d",&a[i].b,&a[i].q); toSort (A +1, a+n+1, CMP); + - intBeg =0, end =0, ans =0; the * for(inti =1; I <= n;i++){ $Beg + =a[i].b;Panax Notoginseng if(Beg + a[i].q >= end) End = Beg +a[i].q; - the //printf ("i =%d Beg =%d end =%d\n", i,beg,end); + } Aprintf"Case %d:%d\n",++Kase,max (Beg,end)); the } + return 0; -}
View Code
UVa 11729 Commando War "greedy"