【贪心】【HDOJ-1789】Doing Homework again

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
 
/***********************************************************************************************************************
题意:有n份作业要做,每份必须在一定时间内完成,否则扣分,求扣分最少的
思路:按扣分的大小降序排序,然后将这份作业尽可能的安排的晚,如果无法安排,就扣分
***********************************************************************************************************************/
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
using namespace std;
typedef struct 
{
    int d, r;
}node;
node a[1000+10];
bool flag[1000+10];
bool cmp(node a, node b)
{
    return a.r > b.r;
}
int main()
{
    freopen("data.in" , "r" , stdin);
    int t;
    scanf("%d", &t);
    while(t--)
    {
        int ans = 0;
        memset(flag , true , sizeof(flag));
        int n;
        scanf("%d", &n);
        for(int i = 0 ; i < n ; i ++)
            scanf("%d", &a[i].d);
        for(int i = 0 ; i < n ; i ++)
            scanf("%d", &a[i].r);
        sort(a , a + n , cmp);
        for(int i = 0 ; i < n ; i ++)
        {
            int mark = 0x7fffffff;
            for(int j = a[i].d ; j > 0 ; j --)
            {
                if(flag[i])
                {
                    flag[i] = false;
                    mark = -1;
                    break;
                }
            }
            if(mark == 0x7fffffff)
                ans += a[i].r;
        }
        printf("%d\n" , ans);
    }
    return 0;
}

 

posted @ 2014-02-22 14:34  AHU_树  阅读(460)  评论(0编辑  收藏  举报