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);
}
}

杭电 1789 Doing Homework again (贪心 求最少扣分)的更多相关文章

  1. Doing Homework again(杭电1789)

    Doing Homework again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  2. HDOJ.1789 Doing Homework again (贪心)

    Doing Homework again 点我挑战题目 题意分析 给出n组数据,每组数据中有每份作业的deadline和score,如果不能按期完成,则要扣相应score,求每组数据最少扣除的scor ...

  3. hdu 1789 Doing HomeWork Again (贪心算法)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1789 /*Doing Homework again Time Limit: 1000/1000 MS ...

  4. HDU 1789 - Doing Homework again - [贪心+优先队列]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1789 Time Limit: 1000/1000 MS (Java/Others) Memory Li ...

  5. HDU 1789 Doing Homework again(贪心)

    Doing Homework again 这只是一道简单的贪心,但想不到的话,真的好难,我就想不到,最后还是看的题解 [题目链接]Doing Homework again [题目类型]贪心 & ...

  6. 杭电 1009 FatMouse' Trade (贪心)

    Problem Description FatMouse prepared M pounds of cat food, ready to trade with the cats guarding th ...

  7. 杭电 4883 TIANKENG’s restaurant (求饭店最少需要座椅)

    Description TIANKENG manages a restaurant after graduating from ZCMU, and tens of thousands of custo ...

  8. 杭电 2111 Saving HDU (贪心)

    Description 话说上回讲到海东集团面临内外交困,公司的元老也只剩下XHD夫妇二人了.显然,作为多年拼搏的商人,XHD不会坐以待毙的.   一天,当他正在苦思冥想解困良策的时候,突然想到了自己 ...

  9. 杭电1019 Least Common Multiple【求最小公倍数】

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1019 解题思路:lcm(a,b)=a*b/gcd(a,b) 反思:最开始提交的时候WA,以为是溢出了, ...

随机推荐

  1. Go JSON嵌套解析失败

    //结构体成员变量名首字母要大写,要小写需要用tag,请看范例. //如果没有tag,嵌套时就无法解析属性,解析失败就是空值. type messageRow struct { UserID stri ...

  2. 安装 Apache Commons Logging API步骤

    下载地址:  http://commons.apache.org/logging/ 

  3. LBP特征 学习笔记

    这几天一直在做人脸识别的项目,有用到LBP特征,但是毫无头绪,师姐这几天也比较忙,没有时间来指导我,随自己找相应的介绍LBP的博文来看,现在总算有了一个大体的思路了,就写下来吧 注:参考博文: 目标检 ...

  4. [USACO 2012 Feb Gold] Cow Coupons【贪心 堆】

    传送门1:http://www.usaco.org/index.php?page=viewproblem2&cpid=118 传送门2:http://www.lydsy.com/JudgeOn ...

  5. ACM经历与感悟合集

    ACM经历与感悟合集 ACM起步要点总结(转哈工大) ACM 荣耀之路-学习方法 ACM感悟 一位ACMer过来人的心得 ACM经历总结 大学ACM的总结 ACM大牛的退役贴 各大牛退役总结帖 女生应 ...

  6. Oracle10g安装过程中ORA-27125问题解决

    Oracle10g在CentOS7的安装过程中报错如下错误信息: ORA-: unable to create shared memory segment 解决办法: [root@dbsrv3 dat ...

  7. 线程间的参数传递 分类: linux c/c++ 2014-06-15 17:48 607人阅读 评论(0) 收藏

    在多线程编程中,常常需要从主线程传递参数给子线程或在主线程中获得子线程的计算结果, 若使用全局变量实现,必然需要对临界区保护,因此导致大量的切换工作造成效率的低下: 而利用进程间的参数传递可以解决这一 ...

  8. java批处理、MySQL批处理

    e: cd MySQL\bin mysql -uroot -proot @pause MySQL批处理.bat e: cd JAVA\jdk1.8.0_77\bin javac Hello.java ...

  9. 对char类型数组的英文字母进行冒泡排序

    import java.util.Arrays; import java.util.Scanner; public class Demo02 { public static void main(Str ...

  10. 224 Basic Calculator 基本计算器

    实现一个基本的计算器来计算一个简单的字符串表达式. 字符串表达式可以包含左括号 ( ,右括号),加号+ ,减号 -,非负整数和空格 . 假定所给的表达式语句总是正确有效的. 例如: "1 + ...