hdu1789

来源:互联网 发布:锤子软件下载 编辑:程序博客网 时间:2024/06/05 14:12

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 reduced 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 reduced scores.
Output
For each test case, you should output 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

/*很常规的贪心,很容易按照时间期限进行贪心,那样是不行的,我们要按照分数贪心,经分数从大到小排序,按照分数的顺序枚举每天的期限用掉一天就把当天标记,然后每次向前找如果找不到空着的一天那么就减分*/


#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>using namespace std;struct node{    int time, score, id;    bool operator < (const node &a) const{        if(score == a.score)            return time < a.time;        return score > a.score;    }}nn[1000+10];int use[1000+10];int main(){    int t;    scanf("%d", &t);    while(t--){        memset(use, 0, sizeof(use));        use[0] = 1;        int n;        scanf("%d", &n);        for(int i = 1; i <= n; i++){            scanf("%d", &nn[i].time);            nn[i].id = 0;        }        for(int i = 1; i <= n; i++)            scanf("%d", &nn[i].score);        sort(nn + 1, nn+n+1);        int sum = 0;        for(int i = 1; i <= n; i++){            int flag = 0;            for(int j = nn[i].time; j >= 1; j--){                if(!use[j]){                    use[j] = 1;                    flag = 1;                    break;                }            }            if(!flag)                sum += nn[i].score;        }        printf("%d\n", sum);    }    return 0;}


0 0