杭电1789Doing Homework again

来源:互联网 发布:网络诈骗要判几年 编辑:程序博客网 时间:2024/04/28 06:46
E - Doing Homework again
Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u
Submit Status

Description

zichen 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 zichen 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 zichen 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<stdio.h>#include<string.h>#include<algorithm>using namespace std;struct node{int d,s;}num[1010];bool cmp(node a,node b){if(a.s==b.s)return a.d<b.d;elsereturn a.s>b.s;}int main(){int t,n,i,j,sum;int visit[1010];scanf("%d",&t);while(t--){memset(visit,0,sizeof(visit));scanf("%d",&n);for(i=0;i<n;i++)scanf("%d",&num[i].d);for(i=0;i<n;i++)scanf("%d",&num[i].s);sort(num,num+n,cmp);sum=0;    for(i=0;i<n;i++)    {    if(!visit[num[i].d])    visit[num[i].d]=1;    else    {    for(j=num[i].d;j>0;j--)    {    if(!visit[j])    {      visit[j]=1;      break;        }}if(j==0)sum+=num[i].s;}}printf("%d\n",sum);}return 0;}
0 0
原创粉丝点击