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
 #include<cstdio>
#include<algorithm>
using namespace std;
struct stu
{
int d,s;
}a[];
bool cmp(stu a,stu b)
{
if(a.s != b.s) return a.s>b.s;
else return a.d<b.d;
}
int main()
{ int t,n,j;
scanf("%d",&t);
while(t--)
{
int b[]={,};
int sum=;
scanf("%d",&n);
for(int i = ; i < n; i++)
{
scanf("%d",&a[i].d);
}
for(int i = ; i < n; i++)
{
scanf("%d",&a[i].s);
}
sort(a,a+n,cmp); /* for(int i = 0;i < n;i++)
printf("--%d--%d--\n",a[i].d,a[i].s);
*/ for(int i=;i<n;i++)
{
for(j=a[i].d;j>;j--)
{
if(b[j] == )
{
b[j]=;
break;
}
}
if(j == ) sum+=a[i].s;
}
printf("%d\n",sum);
}
}

最新文章

  1. [原]分享一下我和MongoDB与Redis那些事
  2. BrnShop mvc3升级mvc4
  3. MyCAT实现MySQL的读写分离
  4. How to create a project with Oracle Policy Modeling
  5. Android官方提供的下拉刷新控件——SwipeRefreshLayout
  6. HDU 1394Minimum Inversion Number(线段树)
  7. java程序练习:x进制转Y进制
  8. Dijkstra in python
  9. Loadrunner负载机agent
  10. Bash判断是否是root
  11. Python for else 循环控制
  12. verilog中always块延时总结
  13. Git 忽略特殊文件的功能
  14. [LeetCode] 33. Search in Rotated Sorted Array_Medium tag: Binary Search
  15. 用NextResult方法取得多个Result Set
  16. 在不安装oracle客户端的情况下,使用PLSQL
  17. 利用反射C#获取事件列表
  18. 24.ArrayBuffer
  19. Unity3d游戏开发中使用可空类型(Nullable Types)
  20. 一些有趣的使用function

热门文章

  1. Unix\Linux | 总结笔记 | 查看文件的方式
  2. HDU 6096 树套树
  3. [ZPG TEST 109] 兔子跳跃【构图】
  4. 设置UITableViewCell 选中时的背景颜色
  5. 利用正则将xml数据解析为数组
  6. Android 中保存数据到文件中
  7. WP7 开发资料
  8. Redux中的异步操作
  9. 常用css属性拓展
  10. js几个逻辑运算符的形象概括