Doing Homework again

匿名 (未验证) 提交于 2019-12-02 23:59:01

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
#include<iostream> #include<cstdio> #include<algorithm> #include<cstring> using namespace std; int t,n,v[1010]; struct Work{ 	int d; 	int c; }w[1010]; bool comp(Work a,Work b) { 	return a.c>b.c; } int main() { 	cin>>t; 	while(t--) 	{ 		memset(v,0,sizeof(v));	 		int sum=0; 		cin>>n; 		for(int i=1;i<=n;i++) 			cin>>w[i].d; 		for(int i=1;i<=n;i++) 			cin>>w[i].c,sum+=w[i].c; 		sort(w+1,w+1+n,comp);			 		for(int i=1;i<=n;i++) 		{ 			for(int j=w[i].d;j>0;j--) 			if(!v[j]){ 				v[j]=1; 				sum-=w[i].c; 				break; 			} 			 		} 		cout<<sum<<endl; 	} 	 	return 0;	 } 

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!