Doing Homework again
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 8847 Accepted Submission(s): 5212
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.
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恩,题目大意就是说,做作业,在最后期限之前仍没上交就倒扣分数,然后就是每门功课的最后期限和所要倒扣的分数,求如何安排做作业的先后顺序使得扣的分数最小,一天可以完成一门功课。贪心嘛,想要尽可能的扣的分数小,按分数排序,然后开一个数组记录在那天有木有已经安排作业,若有就将天数往前推。例如最后一组测试数据。排序后7(4)6(2)5(4)4(3)3(1)2(4)1(6);这样到第三个时就会发现第四天已经有安排了,就将5(3)然后第四个就再往前推4(1)之后第五个发现前面每天都有安排了就必须舍弃了,即是要被倒扣的分数,然后是1(6),倒扣了5分。#include<cstdio> #include<cstring> #include<algorithm> using namespace std; int flag[1010]; struct node { int sco,day; }w[1010]; int cmp(node a,node b) { if(a.sco==b.sco) return a.day<b.day; return a.sco>b.sco; } int main() { int c,n,i,s; scanf("%d",&c); while(c--) { scanf("%d",&n); s=0; for(i=0;i<n;++i) scanf("%d",&w[i].day); for(i=0;i<n;++i) scanf("%d",&w[i].sco); sort(w,w+n,cmp); memset(flag,0,sizeof(flag)); for(i=0;i<n;++i) { int j=w[i].day; if(flag[j]==0) flag[j]=1; else { for(;j>0;j--) { if(flag[j]==0) { flag[j]=1; break; } else if(j==1) { s+=w[i].sco; } } } } printf("%d\n",s); } return 0; }