I - Doing Homework again

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d
& %I64u

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
my answer:
#include<iostream>
#include<algorithm>
using namespace std;
typedef struct st{
int day;
int score;
}st;
bool cmp(st a,st b){
return a.score>b.score;
}
int main()
{
int n,T;
cin>>T;
while(cin>>n)
{
st a[1000];
int vis[1000]={0};
for(int i=0;i!=n;i++)
cin>>a[i].day;
for(int i=0;i!=n;i++)
cin>>a[i].score;
int b[1000];
sort(a,a+n,cmp);
int sum=0;
for(int j=0;j<n;j++){
if(vis[a[j].day]){ int k=a[j].day;
while(k>0&&vis[k])k--;
if(k<=0){sum+=a[j].score;}
else vis[k]=1;
}
else
{
vis[a[j].day]=1;
}
}
cout<<sum<<endl;
}
return 0;
}

I - Doing Homework again的更多相关文章

  1. bzoj 4320: ShangHai2006 Homework

    4320: ShangHai2006 Homework Time Limit: 10 Sec Memory Limit: 128 MB Description 1:在人物集合 S 中加入一个新的程序员 ...

  2. HDU 1789 Doing Homework again(贪心)

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

  3. hdu-1789-Doing Homework again

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

  4. HDU 1789 Doing Homework again (贪心)

    Doing Homework again http://acm.hdu.edu.cn/showproblem.php?pid=1789 Problem Description Ignatius has ...

  5. Doing Homework 状态压缩DP

    Doing Homework 题目抽象:给出n个task的name,deadline,need.  每个任务的罚时penalty=finish-deadline;   task不可以同时做.问按怎样的 ...

  6. 机器学习 —— 概率图模型(Homework: Exact Inference)

    在前三周的作业中,我构造了概率图模型并调用第三方的求解器对器进行了求解,最终获得了每个随机变量的分布(有向图),最大后验分布(双向图).本周作业的主要内容就是自行编写概率图模型的求解器.实际上,从根本 ...

  7. hdoj 1789 Doing Homework again

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

  8. homework做了些什么?

    第一步:get_new_guid_uid_pairs_{$ymd} 参数是时间和100上的文件. 那么100上的文件是从哪里来的呢? 我们进入到100机器上,打开root权限下的cron,看到如下内容 ...

  9. HDU 1074 Doing Homework (dp+状态压缩)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1074 题目大意:学生要完成各科作业, 给出各科老师给出交作业的期限和学生完成该科所需时间, 如果逾期一 ...

  10. hdu1074 Doing Homework(状态压缩DP Y=Y)

    Doing Homework Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) T ...

随机推荐

  1. javaScript 工作必知(八) 属性的特性 值、写、枚举、可配置

    属性的特性 每个对象都拥有属性,属性具有哪些特性呢? 1.属性具有值.  2.属性是否是可写的.            3.是否是可枚举的.            4.是否是可配置的.   " ...

  2. self

    self在对象方法中使用,指代调用当前对象方法的对象.可以利用self->属性名称的方法访问成员变量 self在类方法中使用,其指代的是当前类. 使用总结: self 谁调用当前方法,self就 ...

  3. vs2010快捷方式

    [窗口快捷键] Ctrl+W,W: 浏览器窗口  Ctrl+W,S: 解决方案管理器  Ctrl+W,C: 类视图  Ctrl+W,E: 错误列表  Ctrl+W,O: 输出视图  trl+W,P: ...

  4. js中跳转

    <li><a href="javascript:recordRescSifting('+subject.subId+');">'+subject.subNa ...

  5. Java程序执行Linux命令

    Java程序中要执行linux命令主要依赖2个类:Process和Runtime 首先看一下Process类: ProcessBuilder.start() 和 Runtime.exec 方法创建一个 ...

  6. Linux学习之停止进程

    首先,用ps查看进程,方法如下: ps -ef ……smx       1822     1  0 11:38 ?        00:00:49 gnome-terminalsmx       18 ...

  7. Java中Overload和Override的区别

    由于项目正式收工,闲来无事突然发现以前的文档上有一个问题介绍的不是很详细 override(重写,覆盖) ​​ 1.方法名.参数.返回值相同. ​2.子类方法不能缩小父类方法的访问权限. 3.子类方法 ...

  8. querySelectorAll的BUG

    querySelector和querySelectorAll是W3C提供的新的查询接口 目前 IE8/9及Firefox/Chrome/Safari/Opera 的最新版已经支持它们. 但是Eleme ...

  9. 使用mysql_query()方法操纵数据库以及综合实例

    1.利用insert 语句添加记录 <? require('conn.php'); mysql_query( "insert into lyb ( title, content, au ...

  10. html中上标、下标、删除字、小号字等

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...