Doing homework again
Time Limit: 1000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 6833 accepted submission (s): 4070
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 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# Include <stdio. h> # include <string. h ># include <algorithm> using namespace STD; int STR [1010]; // used to mark whether the day is occupied. 0 is not used at the beginning, and 1 is used when it is used. Struct st {int time, fen;} data [1010]; int CMP (st a, St B) // sort the deduction points from high to low. If the deduction points are the same, the subject is short before the examination. {If (A. Fen! = B. FEN) return. fen> B. fen; else return. time <B. time ;}int main () {int I, j, t, n; scanf ("% d", & T); While (t --) {memset (STR, 0, sizeof (STR); scanf ("% d", & N); for (I = 0; I <n; I ++) {scanf ("% d ", & Data [I]. time) ;}for (I = 0; I <n; I ++) {scanf ("% d", & Data [I]. FEN);} Sort (data, data + N, CMP); int sum = 0; for (I = 0; I <n; I ++) {J = data [I]. time; while (j) // give priority to the subjects with more points deducted on the last day of the term. {If (! STR [J]) // if it is not occupied that day, it occupies that day. Jump out of the while loop and consider the subject that has been deducted multiple times. {STR [J] = 1; break;} j --; // if the previous day is occupied, check whether the previous day is occupied.} If (j = 0) sum + = data [I]. fen; // if all the days within the validity period have been occupied, points must be deducted.} Printf ("% d \ n", sum);} return 0 ;}
Doing homework again (hangdian 1789)