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. 面试杂谈:面试程序员时都应该考察些什么?<转>

    一般来说,一线成熟企业技术岗位的典型招聘流程分为以下几个步骤: 初筛:一般由直接领导的技术经理或HR进行,重点考察教育和工作经历 一面:一般由可能直接与之共事的工程师进行,重点考察基础和工作能力 二面 ...

  2. 《windows核心编程系列》十六谈谈内存映射文件

    内存映射文件允许开发人员预订一块地址空间并为该区域调拨物理存储器,与虚拟内存不同的是,内存映射文件的物理存储器来自磁盘中的文件,而非系统的页交换文件.将文件映射到内存中后,我们就可以在内存中操作他们了 ...

  3. python中字典的陷阱

    把字典与列表组合,如 i=20 s=[]#定义一个空列表 b={'d':i}#定义一个字典 while i>0: i=i-1 b['d']=i#更新字典的值 s.append(b) print( ...

  4. [poj2096] Collecting Bugs【概率dp 数学期望】

    传送门:http://poj.org/problem?id=2096 题面很长,大意就是说,有n种bug,s种系统,每一个bug只能属于n中bug中的一种,也只能属于s种系统中的一种.一天能找一个bu ...

  5. Maven环境搭建操作记录

    Maven官方网站: http://maven.apache.org/index.html Maven下载地址: http://maven.apache.org/download.cgi Maven历 ...

  6. Linux磁盘分区、格式化和挂载

    一.查看磁盘使用 [root@iZ88rvassw1Z ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/vda1 40G .3G 3 ...

  7. Android偏好设置(5)偏好设置界面显示多个分组,每个分组也有一个界面

    1.Using Preference Headers In rare cases, you might want to design your settings such that the first ...

  8. AJPFX关于TreeSet集合的介绍

    需求:键盘录入5个学生信息(姓名,语文成绩,数学成绩,英语成绩),按照总分从高到低输出到控制台.分析:1.创建键盘录入对象:          2.创建TreeSet集合,使用匿名内部类实现Compa ...

  9. springmvc 的配置 annotation-config/annotation-drive/ component-scan 区别

    1. <context:annotation-config /> 作用隐式的配置注解的加载类,默认的加载了AutowiredAnnotationBeanPostProcessor(auto ...

  10. php高效率对一维数组进行去重

    $input = array("a" => "green", "red", "b" => "gre ...