标签:
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.
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.
For each test case, you should output the smallest total reduced score, one line per test case.
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
0 3 5
1 #include<stdio.h> 2 #include<string.h> 3 #include<algorithm> 4 using namespace std; 5 6 const int MAXN=1010; 7 8 struct Node 9 { 10 int d,s; 11 }node[MAXN]; 12 13 bool used[10000]; 14 15 bool cmp(Node a,Node b) 16 { 17 if(a.s==b.s) 18 { 19 return a.d<b.d; 20 } 21 return a.s>b.s; 22 } 23 24 int main() 25 { 26 int T; 27 int n; 28 int j; 29 scanf("%d",&T); 30 while(T--) 31 { 32 scanf("%d",&n); 33 for(int i=0;i<n;i++) scanf("%d",&node[i].d); 34 for(int i=0;i<n;i++) scanf("%d",&node[i].s); 35 sort(node,node+n,cmp); 36 memset(used,false,sizeof(used)); 37 int ans=0; 38 for(int i=0;i<n;i++) 39 { 40 for(j=node[i].d;j>0;j--) 41 { 42 if(!used[j]) 43 { 44 used[j]=true; 45 break; 46 } 47 } 48 if(j==0) 49 ans+=node[i].s; 50 } 51 printf("%d\n",ans); 52 } 53 return 0; 54 }
标签:
原文地址:http://www.cnblogs.com/to-creat/p/4938963.html