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. Elasticsearch 5.0 磁盘空间节省策略的认识

    前言:本文是当时QQ群员讨论磁盘空间如何优化,我搜了下类似的文章,结合官方文档做了一些总结 参考文章1 参考文章2 如果你有疑问,可以联系我参与讨论,或者去原文查看. NOTE: 磁盘空间节省问题,是 ...

  2. 讲解——Trie树(字典树)

          Trie树(字典树) 一.引入 字典是干啥的?查找字的. 字典树自然也是起查找作用的.查找的是啥?单词. 看以下几个题: 1.给出n个单词和m个询问,每次询问一个单词,回答这个单词是否在单 ...

  3. 数据挖掘_wget整站下载

    你应该了解的所有wget命令 翻译自All the Wget Commands You Should Know 如何下载整个网站用来离线浏览?怎样将一个网站上的所有MP3文件保存到本地的一个目录中?怎 ...

  4. 逃出克隆岛 (codevs 2059)

    较普通的走迷宫的题 传送门 :codevs 2059 逃出克隆岛 思路 :BFS 即可    PS :传送门 不必重复使用 #include <iostream> #include < ...

  5. 文档在线预览开源实现方案一:OpenOffice + SwfTools + FlexPaper

    在文档在线预览方面,项目组之前使用的是Microsoft office web apps, 由于该方案需要按照微软License付费,项目经理要我预研一个文档在线预览的开源实现方案.仔细钻入该需求发现 ...

  6. [转]numpy性能优化

    转自:http://blog.csdn.net/pipisorry/article/details/39087583 http://blog.csdn.net/pipisorry/article/de ...

  7. ConfigurationManager 缓存刷新

    服务没有停止的情况下,如果修改了配置,如果不刷新,是不会生效的,需要在每次重新读取配置前刷新配置文件,具体如下: ConfigurationManager.RefreshSection("a ...

  8. 在vim编辑器中,删除操作

    我这里在编辑一个很大的文件,有几万行,都是文件名sheetid, 中间有很多空行,我现在要做的事情就有要把这个文件中的空行都删除掉,这个本来想在ultraedit里面完成的,结果弄了好半天都没有搞定, ...

  9. SQLite模糊查找(like)

    select UserId,UserName,Name,Sex,Birthday,Height,Weight,Role from xqhit_Users where UserName like &qu ...

  10. Java中eclipse中添加源码依赖

    Window ->Preferences ->Java->instanlled jres  ->editrt.jarsource attachment一般在jdk的目录下的sr ...