Doing Homework again
Problem DescriptionIgnatius 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.?
InputThe 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.
?
OutputFor 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
?
Author
/*
第一步按照分数score从大到小排序,如果score相等,则按照截止时间deadline从前往后排。
然后开始选择,让当前的课排在其deadline上面,如果这一天已经被占用了,那么就往前循环,有位置了就安排,
没位置了就ans+=score。
*/
#include
#include
#include
using namespace std;
struct homework
{
int time;
int score;
}hm[1011];
bool cmp(homework a,homework b)
{
if(a.score>b.score)
return true;
else if(a.time0;j--)//作业是可以当天做的
{
if(work[j]==0)//如果这一天没有任务。
{
work[j]=1;
break;
}
}
if(j<=0)//前面没有可用的时间
ans+=hm[i].score;
}
printf("%d\n",ans);
}
return 0;
}