hdu 1789Doing Homework again

来源:互联网 发布:3dmax软件 编辑:程序博客网 时间:2024/06/05 00:39
 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

这道题排序之后,逆序处理天数,先把每一个扣分大小都压进优先队列里面,之后用当前的天减去上一个天,即这两份作业之间有多少空余的天,让这些空余的天数做最大分数的作业,直接把优先队列队首元素pop出来即可,最后队列里面剩余的就是没有完成的作业.

#include<bits/stdc++.h>using namespace std;const int N=1100;struct node{    int a,b;}app[N];int dp[N];bool cmp(node x,node y){    return x.a<y.a||x.a==y.a&&x.b<y.b;}int main(){    int t,n,mx;    cin>>t;    while(t--)    {        priority_queue<int,vector<int>,less<int> >q;        memset(dp,0,sizeof dp);        cin>>n;        mx=0;        for(int i=1;i<=n;i++)            cin>>app[i].a;        for(int i=1;i<=n;i++)           cin>>app[i].b;        sort(app+1,app+1+n,cmp);        for(int i=n;i>=1;i--)        {            q.push(app[i].b);            int cnt=app[i].a-app[i-1].a;            while(cnt--)            {                if(!q.empty())                    q.pop();            }        }        int sum=0;        while(!q.empty())            sum+=q.top(),q.pop();        cout<<sum<<endl;    }    return 0;}