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. eclipse安装

    1.下载破解版本 地址:http://www.oyksoft.com/soft/1250.html 2.解压下载包,直接运行eclipse.exe  3.安装过程中如果遇到问题 1).如果遇到erro ...

  2. 网页视频下载牛逼工具,支持各种格式转换,比如腾讯视频格式qlv转mp4

    这种思路真是创新,原文地址:http://jingyan.baidu.com/article/5225f26b03f047e6fb090860.html 软件工具名字:维棠下载. 上图: 1:搜索视频 ...

  3. Linux CentOS 7 YUM 安裝 MySQL 5.7

    MySQL YUM 源:http://dev.mysql.com/downloads/repo/yum/ # 下載源 $ wget http://dev.mysql.com/get/mysql57-c ...

  4. Openjudge-NOI题库-二维数组回形遍历

    题目描述 Description 给定一个row行col列的整数数组array,要求从array[0][0]元素开始,按回形从外向内顺时针顺序遍历整个数组.如图所示:  输入输出格式 Input/ou ...

  5. Saltstack Master 配置文件详解

    #主配置 /etc/salt/master interface 默认值:0.0.0.0(所有的网络地址接口) 绑定到本地的某个网络地址接口 interface: 192.168.30.131 publ ...

  6. php stdClass类的用法

    stdClass是PHP的一个基类,所有的类几乎都继承这个类,所以任何时候任何地方都可以被new,可以让这个变量成为一个object.同时,这个基类又有一个特殊的地方,就是没有方法.凡时用new st ...

  7. git上传报错的解决方案

    刚创建的github版本库,在push代码时出错:$ git push -u origin masterTo git@github.com:******/Demo.git ! [rejected] m ...

  8. webp图片详解

    WebP(发音 weppy),是一种支持有损压缩和无损压缩的图片文件格式,派生自图像编码格式 VP8.根据 Google 的测试,无损压缩后的 WebP 比 PNG 文件少了 45% 的文件大小,即使 ...

  9. PortMon(电脑开放端口检查工具) 3.03 免费绿色版

    软件名称: PortMon(电脑开放端口检查工具) 3.03 免费绿色版 软件语言: 英文 授权方式: 免费软件 运行环境: Win7 / Vista / Win2003 / WinXP / Win2 ...

  10. windows下寻找端口

    netstat -aon|findstr "5037" 找到占用5037的进程号: 根据进程号杀死进程 taskkill /pid 5136 /f tasklist|findstr ...