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 to arrange the order of doing homework to minimize the reduced score. Inputthe input 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 the output of the smallest total reduced score, one line per test case. Sample Input
333 3 310 5 131 3 16 2 371 4 6 4 2 4 33 2 1 7 6 5 4
Sample Output
035
AuthorlcySource2007 Provincial Training Team Practice (10) _ Thanks to DOOMIII
#include <stdio.h>#include<math.h>#include<stdlib.h>#include<string.h>#include<algorithm>using namespacestd;Const intmaxn= ++Ten;structnode{intDl,sco; BOOLFlag//FLAF indicates that you can complete}A[MAXN];BOOLCMP (node A1,node a2) {if(A1.DL!=A2.DL)returna1.dl<a2.dl; Else returnA1.sco>A2.sco;}intMain () {intN,n,i; scanf ("%d",&N); while(n--) {scanf ("%d",&N); for(i=0; i<n;i++) scanf ("%d",&a[i].dl); for(i=0; i<n;i++) scanf ("%d",&A[i].sco); for(i=0; i<n;i++) a[i].flag=true; Sort (A,a+n,cmp); intday=1, res=0; for(i=0; i<n;i++) { if(a[i].dl>=Day ) { Day++; Continue; } intp=a[i].sco,pos=i; for(intj=0; j<i;j++) { if(a[j].sco<p&&a[j].flag==1) {p=A[j].sco; POS=J; }} Res+=p; A[pos].flag=0; } printf ("%d\n", RES); } return 0;}
Hdu1789doing homework Again (greedy)