Description
Test instructions is a hdu of God's cattle from the world final heroic return. Then he has to mend his homework. A total of n jobs will take one day to complete each job. However, each job has a due date if it exceeds the due date, it will deduct the due date of n jobs and if it is more than the cutoff date to calculate the order of how to do the work of the least calculate the minimum deduction score input
The 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.
Output
For the should output of the smallest total reduced score, one line per test case.
Sampleinput
333 3 310 5 131 3 16 2 371 4 6 4 2 4 33 2 1 7 6 5 4
Sampleoutput
035
First, according to the order of the points from the big to the small, the same score according to the cutoff date from small to large order. Then, in order, start looking for the time that is not occupied from the due date. If you can't find it, add it to the penalty point.
1#include <stdio.h>2#include <string.h>3#include <algorithm>4 using namespacestd;5 6 Const intmaxn=1010;7 8 structNode9 {Ten intd,s; One }NODE[MAXN]; A - BOOLused[10000]; - the BOOLCMP (Node a,node B) - { - if(a.s==B.S) - { + returna.d<B.D; - } + returnA.s>B.S; A } at - intMain () - { - intT; - intN; - intJ; inscanf"%d",&T); - while(t--) to { +scanf"%d",&n); - for(intI=0; i<n;i++) scanf ("%d",&node[i].d); the for(intI=0; i<n;i++) scanf ("%d",&node[i].s); *Sort (node,node+n,cmp); $memset (Used,false,sizeof(used));Panax Notoginseng intans=0; - for(intI=0; i<n;i++) the { + for(j=node[i].d;j>0; j--) A { the if(!Used[j]) + { -used[j]=true; $ Break; $ } - } - if(j==0) theans+=Node[i].s; - } Wuyiprintf"%d\n", ans); the } - return 0; Wu}View Code
Doing Homework Again