D - Doing Homework again扣分最少

来源:互联网 发布:藏地密码 知乎 编辑:程序博客网 时间:2024/04/28 02:53


Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u 

Submit Status 

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 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 <stdio.h>#include <algorithm>using namespace std;struct p{int day;int score;int flag;}s[1000];int cmp(p a,p b){    if(a.day==b.day)        return a.score>b.score;    else        return a.day<b.day;}int main(){    int T,t;    scanf("%d",&T);    while(T--)    {        scanf("%d",&t);        int i;        for(i=0;i<t;i++)            scanf("%d",&s[i].day);        for(i=0;i<t;i++)            scanf("%d",&s[i].score);        for(i=0;i<t;i++)        s[i].flag=-1;        sort(s,s+t,cmp);        int day=1,j,v,min;        for(i=0;i<t;i++)        {             if(day<=s[i].day)            {              s[i].flag=1;                day++;             }            else            {              min=s[i].score;                v=-1;                for(j=i-1;j>=0;j--)                {                    if(s[j].flag==1&&s[j].score<min)                    {                  min=s[j].score;                        v=j;                    }                }                if(v>=0)                {                    s[v].flag=-1;                    s[i].flag=1;                }            }        }        int sum=0;        for(i=0;i<t;i++)        {             if(s[i].flag==-1)                sum+=s[i].score;        }        printf("%d\n",sum); }        return 0;}

0 0