Description
Ignatius 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.
Input
The 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.
Output
For each test case, You shocould output the smallest total 0000ced 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
Question: each assignment has a specified time to complete, and the time-out points are deducted for minimum points.
Idea: greedy sorting, and then each one starts from the farthest time, marking the Processing
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int maxn = 1005;struct Node {int day, cost;} node[maxn];int n;int f[maxn];int cmp(Node a, Node b) {return a.cost < b.cost;}int main() {int t;scanf("%d", &t);while (t--) {scanf("%d", &n);for (int i = 0; i < n; i++) {scanf("%d", &node[i].day);if (node[i].day > n)node[i].day = n;}int sum = 0;for (int i = 0; i < n; i++) {scanf("%d", &node[i].cost);sum += node[i].cost;}sort(node, node+n, cmp);memset(f, 0, sizeof(f));for (int i = n-1; i >= 0; i--) for (int j = node[i].day; j >= 1; j--) if (!f[j]) {f[j] = 1;sum -= node[i].cost;break;}printf("%d\n", sum);}return 0;}