首页 > 代码库 > Doing Homework again
Doing Homework again
Doing Homework again
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64uDescription
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
1 #include <iostream> 2 #include <stdio.h> 3 #include <string.h> 4 #include <map> 5 #include <algorithm> 6 using namespace std; 7 typedef struct abcd 8 { 9 int w,l;10 }abcd;11 abcd a[1200];12 bool cmp(abcd x,abcd y)13 {14 if(x.w==y.w)return x.l>y.l;15 return x.w>y.w;16 }17 map<int,int> m;18 int main()19 {20 int t,n,i,j,ans;21 scanf("%d",&t);22 while(t--)23 {24 scanf("%d",&n);25 for(i=0;i<n;i++)26 scanf("%d",&a[i].l);27 for(i=0;i<n;i++)28 scanf("%d",&a[i].w);29 sort(a,a+n,cmp);30 m.clear();31 ans=0;32 for(i=0;i<n;i++)33 {34 if(m[a[i].l]==0)35 {36 m[a[i].l]=1;37 }38 else39 {40 while(a[i].l>0&&m[a[i].l])a[i].l--;41 if(a[i].l>0)m[a[i].l]=1;42 else ans+=a[i].w;43 }44 }45 cout<<ans<<endl;46 }47 }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。