Problem Descriptionignatius have just come back school from the 30th ACM/ICPC. Now he had a lot of homework to do. Every teacher gives him a deadline of handing in the homework. If Ignatius hands in the homework after the deadline, the teacher would reduce his score of the final Test. And now we assume this doing everyone homework always takes one day. So Ignatius wants-to-help him-arrange the order of doing homework to minimize the reduced score. inputthe Inpu T contains several test cases. The first line of the input was a single integer T so is the number of test cases. T test Cases follow. Each test case start with a positive integer N (1<=n<=1000) which indicate the number of homework. Then 2 lines follow. The first line contains n integers this indicate the deadlines of the subjects, and the next line contains N integers that Indicate the reduced scores. outputfor each test case, you should output the smallest total reduced score, one line Per Test case. Sample INPUT3 3 3 3 3 5 1 3 1 3 1 6 2 3 7 1 4 6 4 2 4 3 3 2 1 7 6 5 4 sample Output0 3 5 //Oh, I feel so stupid, I don't want to see the puzzle To.. decided to brush up on the greedy recently, understand understand well
#include <iostream>#include<algorithm>#include<cstring>using namespacestd;intans;structnode{intTime ; intFen;} work[1005];BOOLcmpConstNode &a,ConstNode &b) { if(a.fen>B.fen)return true; Else if(a.fen==B.fen) {if(a.time<b.time)return true; Else return false; } Else return false;}intMain () {intT,n; intss[1005]; CIN>>T; while(t--) {memset (ss,0,sizeof(ss)); Ans=0; CIN>>N; for(intI=0; i<n;i++) Cin>>Work[i].time; for(intI=0; i<n;i++) Cin>>Work[i].fen; Sort (Work,work+n,cmp); //for (int i=0;i<n;i++)//cout<<work[i].time<< "" <<work[i].fen<<endl; for(intI=0; i<n;i++) { intj=Work[i].time; while(j--) { if(ss[j]==0) {Ss[j]=1; Break; } } if(ss[j]!=1) ans+=Work[i].fen; } cout<<ans<<Endl; } return 0;}
HDU 1789 Doing Homework again