首页 > 其他 > 详细

Doing Homework again

时间:2014-07-15 08:15:08      阅读:394      评论:0      收藏:0      [点我收藏+]
 Doing Homework again
Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u
Submit Status

Description

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

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
 
 
bubuko.com,布布扣
 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             else
39             {
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 }
View Code

 

 
 
 

Doing Homework again,布布扣,bubuko.com

Doing Homework again

原文:http://www.cnblogs.com/ERKE/p/3842038.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!