Doing homework again
Time Limit: 1000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 2969 accepted submission (s): 1707
Problem descriptionignatius has just come back school from the 30th ACM/ICPC. now he has 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 will reduce his score of the final test. and now we assume that doing everyone homework always takes one day. so Ignatius wants you to help him to arrange the order of doing homework to minimize the specified CED score.
Inputthe input contains several test cases. The first line of the input is a single integer t that 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 that indicate the deadlines of the subjects, and the next line contains N integers that indicate the specified CED scores.
Outputfor each test case, You shoshould output the smallest total balanced CED score, one line per test case.
Sample input3 3 3 3 3 10 5 1 3 1 3 1 6 2 3 7 1 4 4 4 3 3 2 1 7 6 5 4
Sample output0 3 5
Authorlcy
Source2007 provincial training team exercise (10) _ Thanks to doomiii
Recommendlcy is first sorted by deduction points from large to small. If the scores are the same, they are sorted by the deadline from small to large .. Then, in order, start from the deadline and find the time that is not occupied. If the score cannot be found, add it to the penalty score for details. Program ..
# Include <stdio. h> # Include < String . H> # Include <Algorithm> Using Namespace STD; Const Int Maxn = 1010 ; Struct Node { Int D, s;} node [maxn]; Bool Used [ 10000 ]; Bool CMP (node A, Node B ){ If (A. S = B. s ){ Return A. D < B. D ;} Return A. S> B. S ;} Int Main (){ Int T; Int N; Int J; scanf ( " % D " ,& T ); While (T -- ) {Scanf ( " % D " ,&N ); For ( Int I = 0 ; I <n; I ++) scanf ( " % D " ,& Node [I]. D ); For ( Int I = 0 ; I <n; I ++) scanf ( " % D " ,&Node [I]. s); sort (node, node + N, CMP); memset (used, False , Sizeof (Used )); Int Ans = 0 ; For ( Int I = 0 ; I <n; I ++ ){ For (J = node [I]. D; j> 0 ; J -- ){ If (! Used [J]) {used [J] = True ; Break ;}} If (J = 0 ) Ans + = Node [I]. s;} printf ( " % D \ n " , ANS );} Return 0 ;}