杭电1789贪心

Doing Homework again

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 10545    Accepted Submission(s): 6179

 

Problem 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

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

#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
struct zuoye
{
    int time;
    int score;
     bool operator < (const zuoye &c){
        return score > c.score;
    }
}f[1010];
int main()
{
    //freopen("C:\\Users\\23535\\Desktop\\in.txt","r",stdin); //输入重定向,输入数据将从D盘根目录下的in.txt文件中读取 
    //freopen("C:\\Users\\23535\\Desktop\\out.txt","w",stdout); //输出重定向,输出数据将保存在D盘根目录下的out.txt文件中 
    int T;
    cin>>T;
    int duibi[1010];
    while(T--)
    {
        int n;
        cin>>n;
        int sum=0;
        //int flag=0;
        memset(duibi,0,sizeof(duibi));
        for(int i=1;i<=n;i++)
        {
            cin>>f[i].time;
        }
        for(int i=1;i<=n;i++)
        {
            cin>>f[i].score;
        }
        sort(f+1,f+n+1);
        /*for(int i=0;i<n;i++)
        {
            cout<<f[i].time<<" "<<f[i].score<<endl;
        }
        */
        for(int i=1;i<=n;i++)
        {
            int flag=0;
            if(duibi[f[i].time]==0)
            {
                duibi[f[i].time]=1;
                flag=1;
            }
            else 
            {
                for(int j=f[i].time-1;j>0;j--)
                {
                    if(duibi[j]==0)
                    {
                        duibi[j]=1;
                        flag=1;
                        break;
                    }
                }
            }
            if(flag==0)
            {
                sum=sum+f[i].score;
            }
            //flag=0;
        }
        cout<<sum<<endl;
    }
    
    
    //fclose(stdin);//关闭重定向输入 
    //fclose(stdout);//关闭重定向输出 
    return 0;
}
                
            

猜你喜欢

转载自blog.csdn.net/hhdmw/article/details/81265505
今日推荐