Problem Description

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

Author

lcy

Source

2007省赛集训队练习赛(10)_以此感谢DOOMIII

#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int maxn=+;
struct node{
int dl,sco;
bool flag;//flag表示可以完成
}a[maxn];
bool cmp(node a1,node a2){
if(a1.dl!=a2.dl)return a1.dl<a2.dl;
else return a1.sco>a2.sco;
}
int main()
{
int N,n,i;
scanf("%d",&N);
while(N--)
{
scanf("%d",&n);
for(i=;i<n;i++)scanf("%d",&a[i].dl);
for(i=;i<n;i++)scanf("%d",&a[i].sco);
for(i=;i<n;i++)a[i].flag=true;
sort(a,a+n,cmp);
int day=,res=;
for(i=;i<n;i++)
{
if(a[i].dl>=day){
day++;
continue;
}
int p=a[i].sco,pos=i;
for(int j=;j<i;j++)
{
if(a[j].sco<p&&a[j].flag==)
{
p=a[j].sco;
pos=j;
}
}
res+=p;
a[pos].flag=;
}
printf("%d\n",res);
}
return ;
}

HDU1789Doing Homework again(贪心)的更多相关文章

  1. HDU1789Doing Homework again(贪婪)

    HDU1789Doing Homework again(贪心) 题目链接 题目大意:给你n们作业的最后期限和过了这个期限没做须要扣的分数.问如何安排能够使得扣分最少. 解题思路:贪心,将扣分多的作业排 ...

  2. 贪心-hdu-1789-Doing Homework again

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1789 题目意思: 有n个作业,每个作业有一个截止日期,每个作业如果超过截止日期完成的时候有一个惩罚值 ...

  3. HDU 1789 Doing Homework again(贪心)

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

  4. hdu-1789-Doing Homework again

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

  5. hdu--1798--Doing Homework again(贪心)

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

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

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

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

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

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

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

  9. I - Doing Homework again(贪心)

    I - Doing Homework again Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & ...

随机推荐

  1. extjs底层源码实现继承分析

    先说明一下在js中一般的继承是怎么写的 var farther=function(name){ this.name=name }; farther.prototype={ constructor:fa ...

  2. gridcontrol如何根据值来动态设置某一行的颜色

    应用场景:当我们使用devexpress gridcontrol wpf控件时.可要会要根据这一行要显示的值来设置相应的颜色 可以通过下面方法来实现 一.先定义一个style <local:Co ...

  3. linux 查看磁盘占用情况

    查看"/usr/local/"路径下,所有文件大小总和.只列出总和,不显示该路径下各子文件的大小. du -sh /usr/local/ 结果显示如下图: 如果要详细显示出各子文件 ...

  4. solr常用命令

    1.启动和关闭 a.启动和重启 启动和重启命令有很多选项让你运行在SolrCloud模式,使用示例配置,以hostname为开头或者非默认端口,指向本地ZooKeeper. bin/solr star ...

  5. ACM北大学习

    在两周的学习下,对ACM竞赛有了更深入地了解.学习到了很多知识,见识到了很多高手,目光放得更长远了.最后的比赛,在100多个队伍中,获得第十八的名次,也不负我的学习.

  6. Objective-C Runtime 运行时之三:方法与消息(转载)

    前面我们讨论了Runtime中对类和对象的处理,及对成员变量与属性的处理.这一章,我们就要开始讨论Runtime中最有意思的一部分:消息处理机制.我们将详细讨论消息的发送及消息的转发.不过在讨论消息之 ...

  7. 分布式缓存Memcached/memcached/memcache详解及区别

    先来解释下标题中的三种写法:首字母大写的Memcached,指的是Memcached服务器,就是独立运行Memcached的后台服务器,用于存储缓存数据的“容器”.memcached和memcache ...

  8. HDU 5877 Weak Pair

    $dfs$序,线段树. 可以统计每一个节点作为$root$的子树上对答案的贡献,可以将树转换成序列.问题就变成了一段区间上求小于等于某个值的数有几个.用线段树记录排好序之后的区间序列,询问的时候,属于 ...

  9. openstack私有云布署实践【10.1 计算nova - kxcontroller节点配置(科兴环境)】

    一.首先登录kxcontroller1创建kx_nova数据库,并赋于远程和本地访问的权限.     mysql -u root -p   CREATE DATABASE kx_nova; GRANT ...

  10. 关于数据汇总方面返回Json数据的小小心得

    在一开始的开发中,计算好相关数据,然后通过 1.拼串 2.实例化Dictory对象再通过JavaScriptSerializer转换为json. 其中,2只适合于二维数据.1适合多维数据,但拼串比较费 ...