题意:
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
3
3
3 3 3
10 5 1
3
1 3 1
6 2 3
7
1 4 6 4 2 4 3
3 2 1 7 6 5 4
Sample Output
0
3
5
伊格纳蒂乌斯刚刚从第30届ACM/ICPC回到学校。现在他有很多家庭作业要做。每个老师都给他交作业的最后期限。如果伊格那丢在最后期限后交作业,老师会降低期末考试的分数。现在我们假设做每个人的家庭作业总是需要一天。所以伊格纳蒂厄斯希望你帮助他安排家庭作业的顺序,以尽量减少分数的减少。

输入

输入包含几个测试用例。输入的第一行是一个整数t,它是测试用例数。接下来是T测试案例。

每个测试用例以一个正整数n(1<=n<=1000)开始,它指示作业的数量。接下来是两行。第一行包含n个表示受试者最后期限的整数,下一行包含n个表示分数减少的整数。

输出

对于每个测试用例,您应该输出最小的总减少分数,每个测试用例一行。

#include<bits/stdc++.h>
using namespace std;
struct work{
    int day,s;
}w[1005];
bool cmp(work x,work y)
{
    if(x.s == y.s)        //分数一样 
        return x.day < y.day;  //时间从小到大排 
    return x.s > y.s;   //分数从大到小排 
}
int main()
{
    int T,n;
    cin >> T;
    while(T--){
        int vis[1005]={0};  //标记该天是否写过作业 
        cin >>n;
        int sum=0,num=0;
        for(int i=0;i<n;i++){
            cin >>w[i].day;
        }
        for(int i=0;i<n;i++){
            cin >>w[i].s;
            sum+=w[i].s;     //一共多少分数 

        }
        sort(w,w+n,cmp);
        for(int i=0;i<n;i++){
            if(vis[w[i].day] == 0){     //若这一天没有写过作业,就让这一份作业在这一天写 
                vis[w[i].day] =1;    //为1 
                num+=w[i].s;       //完成的分数加 
            } 
            else{                     //若写过 
                for(int j=w[i].day-1;j>0;j--){          //查找前几天有没有写过作业, 
                    if(vis[j] == 0){          //在前一天完成作业 
                        vis[j] =1;
                        num+=w[i].s;
                        break;
                    }
                }
            }
        }
        printf("%d\n",sum-num);
    }
}