您的位置:首页 > 大数据 > 人工智能

Doing Homework again

2016-07-26 13:14 281 查看
Doing Homework again

Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u

Submit

Status

Practice

HDU 1789

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

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

FAQ | About Virtual Judge | Forum | Discuss | Open Source Project

All Copyright Reserved ©2010-2014 HUST ACM/ICPC TEAM

Anything about the OJ, please ask in the forum, or contact author:Isun

Server Time: 2016-07-26 13:10:47

#include<cstdio>
#include<algorithm>
using namespace std;
struct node{
int day;
int sco;
bool k;
}a[1011];
bool cmp(node a,node b){
if(a.day==b.day)
return a.sco>b.sco;
return a.day<b.day;
}
int main(){
int T;scanf("%d",&T);
while(T--){
int n; scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%d",&a[i].day);
for(int i=0;i<n;i++){
scanf("%d",&a[i].sco);
a[i].k=true;
}
sort(a,a+n,cmp);

int sum=0;
int k=1;
for(int i=0;i<n;i++){
if(a[i].day>=k){
k++;
continue ;
}
int min=a[i].sco;
int s=i;
for(int j=0;j<i;j++){
if(min>a[j].sco&&a[j].k){
min=a[j].sco;
s=j;
}
}
sum+=min;
a[s].k=false;
}
printf("%d\n",sum);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: