Doing homework again
Time Limit: 1000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 6499 accepted submission (s): 3874
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 specified CED 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 specified CED scores.
Outputfor each test case, You shoshould output the smallest total balanced CED score, one line per test case.
Sample input333 3 310 5 131 3 16 2 371 4 6 4 2 33 2 1 7 6 5 4
Sample output035
Authorlcy
Source2007 provincial training team exercise (10) _ Thanks to doomiii
The greedy strategy of recommendlcy is to first reduce the number of points and then reduce the number of points. So we need to sort the number first and sort the number of points to the front. If the score is the same, put deadline in front. Then, each time I take out a task, if it can be executed on the day of deadline, it will be executed on that day. If not, I will go forward and find the day on which the task can be executed. If there are other tasks in the number of days that can be executed, I will not be able to complete this task, and I will subtract the corresponding score.
1 #include<cstdio> 2 #include<cstring> 3 #include<stdlib.h> 4 #include<algorithm> 5 using namespace std; 6 struct node 7 { 8 int day; 9 int num;10 bool operator<(const node &B)const11 {12 if(num!=B.num)13 return num>B.num;14 else15 return day<B.day;16 }17 }a[1000];18 int vis[1000];19 int main()20 {21 int kase;22 scanf("%d",&kase);23 while(kase--)24 {25 int n,i,j,sum=0,ans=0;26 memset(vis,0,sizeof(vis));27 scanf("%d",&n);28 for(i=1;i<=n;i++)29 scanf("%d",&a[i].day);30 for(i=1;i<=n;i++)31 scanf("%d",&a[i].num);32 sort(a+1,a+n+1);33 for(i=1;i<=n;i++)34 {35 for(j=a[i].day;j>0;j--)36 {37 if(!vis[j])38 {39 vis[j]=1;40 break;41 }42 }43 if(j==0)44 ans+=a[i].num;45 }46 printf("%d\n",ans);47 }48 return 0;49 }
View code