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.
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1789
这道题的意思是输入作业的数量的每份作业的提交的最晚时间和如果晚交所减少的分,然后求出减少最少的分。
思路:先把作业按扣的分从大到小排序,如果分数相同,截至日期先得在前面。排完后,然后逐个考虑,如果截止日期那天有空,就把它放在那天,不然就向前推一天。如果没有空余的天数了,那就把它加进减分里。
#include <iostream>
#include<algorithm>
using namespace std;
int mask[10005];
struct node
{
int score, deadline;
}sd[1005];
int cmp(node a, node b)
{
if (a.score == b.score)
return a.deadline < b.deadline;
return a.score > b.score;
}
int main()
{
int n;
cin >> n;
while (n--)
{
memset(mask, 0, sizeof(mask));
int a,ok,sum=0;
cin >> a;
for (int i = 1;i <= a; i++)
cin >> sd[i].deadline;
for (int i = 1;i <= a; i++)
cin >> sd[i].score;
sort(sd + 1, sd + a + 1,cmp);
for (int i = 1;i <= a; i++)
{
ok = 0;
for (int j = sd[i].deadline; j >=1; j--)
{
if (mask[j] == 0)
{
ok = 1;
mask[j] = 1;
break;
}
}
if (!ok)
sum = sum +sd[i].score;
}
cout << sum << endl;
}
return 0;
}