Title Description
Orz Panda is addicted to one RPG game. To make his character stronger, he has to fulfil tasks to get EXP for higher level. At first he accepted all the tasks. But after he read the rules carefully, he realized the what he had done is stupid.
Rule:
Every task costs 1 time interval.
Every task has a dead line. If you can ' t finish it in time, you had to pay the same amount of gold as the EXP given by this task.
Orz Panda wants to know the minimum amount of gold he have to pay.
Input
The first line has a one integer n, tell what many tasks Orz Panda has accepted.
The second line had n integers ti separated by blank and represent for the ith task ' s dead line.
The third line had n integers ei separated by blank, represent for the
EXP given by the ith task.
(1 <= N, ti, ei <= 1000)
Output
One integer for the minimum amount of gold Orz Panda have to pay.
--The first idea of the body is greed, think of the value of the row to be greedy seems to be right, try it really so
#include <iostream>#include<cstring>#include<cstdio>#include<algorithm>#include<cmath>using namespacestd;structtasknode{intDeadLine; intValue;};structTasknode task[1001];intused[1001];BOOLcmpstructTasknode T1,structTasknode T2) { if(t1. Value = = t2. Value)return(t1. DeadLine <T2. DeadLine); returnT1. Value >T2. Value;}intMain () {intN; while(SCANF ("%d", &n)! =EOF) { inti; for(i=1; i<=n;i++) {scanf ("%d",&Task[i]. DeadLine); } for(i=1; i<=n;i++) {scanf ("%d",&Task[i]. Value); } sort (Task+1, task+1+n,cmp); intAns =0; memset (Used,0,sizeof(used)); for(i=1; i<=n;i++){ intNowT =Task[i]. DeadLine; while(NowT >0&& Used[nowt]) nowt--; if(NowT = =0) {Ans+=Task[i]. Value; } ElseUSED[NOWT] =1; } printf ("%d\n", Ans); } return 0;}
Xidianoj 1120 Gold of Orz Pandas