Doing homework again

来源:互联网 发布:泰森能打几个人知乎 编辑:程序博客网 时间:2024/05/13 22:28
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
333 3 310 5 131 3 16 2 371 4 6 4 2 4 33 2 1 7 6 5 4
Sample Output
035
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;struct node{int day,cut;}work[1005];int cal[2010];bool cmp(node a,node b){if (a.cut != b.cut)return a.cut > b.cut;return a.day < b.day;}int main(){int t;scanf("%d",&t);while (t--){memset(cal,0,sizeof(cal));int n;scanf("%d",&n);for (int i = 0; i < n; ++i){scanf("%d",&work[i].day);}for (int i = 0; i < n; ++i){scanf("%d",&work[i].cut);}sort(work,work+n,cmp);int sign;int sum = 0;for (int i = 0; i < n; ++i){sign = work[i].day;while (sign--){if (!cal[sign]){cal[sign] = 1;  //相同deadline 往前替补 deadline更大更无需担心break;}if (sign == 0)sum += work[i].cut;}}printf("%d\n",sum);}return 0;}

0 0
原创粉丝点击