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. HashMap 的遍历key与value的方法

    HashMap最经常使用的使用方法是依据key增删改查value,有时候会须要知道一个HashMap有多少个keys以及这些keys都是什么,能够用以下的代码实现. 方法1: Map map = ne ...

  2. Jackson 框架,轻易转换JSON【转】

    Jackson 框架,轻易转换JSON Jackson可以轻松的将Java对象转换成json对象和xml文档,同样也可以将json.xml转换成Java对象. 前面有介绍过json-lib这个框架,在 ...

  3. HNU 12850 Garage

    长为H的格子里面放n个长为h的格子 最多会有n+1个空隙 要使每一个空隙长度都小于h (H-h*n)/(n+1)<h n>(H/h-1)/2 #include<bits/stdc++ ...

  4. html系列教程--描述

    什么是 HTML? HTML 是用来描述网页的一种语言. HTML 指的是超文本标记语言 (Hyper Text Markup Language) HTML 不是一种编程语言,而是一种标记语言 (ma ...

  5. Spire PDF for .NET 在ASP.NET中的使用 ---- 并非那么“美好”,有些挫折!

    笔者注:看此文前,请您先看一下上一篇文章吧. 昨天的时候,我测试了一下Spire PDF在WinForm程序中的应用,可以说用起来很简单(请忽略效率问题,没有进行测试).不过在互联网如此发达的今天,适 ...

  6. juce 中的ReferenceCountedObjectPtr

    提供了对引用计数对象的管理,其实也就是操作引用计数对象,当引用计数为零的时候将对象销毁,值得学习的是juce是如果将引用计数对象和它的智能指针结合在一起的,这个后面再加分析 //=========== ...

  7. 判断浏览器 IE 11

    var getOs=function()  {   try {  var u = window.navigator.userAgent.toLocaleLowerCase(),  msie = /(m ...

  8. linux文件名乱码解决办法

    1.linux解压压缩文件乱码 unzip -O CP936 xxx.zip 2.一般文件用convmv sudo convmv -f gbk -t utf-8 -r --notest /your_d ...

  9. VPN服务器搭建好以后的安全防护

    之前讲过VPN的搭建过程,那么搭建完毕后,需要做哪些防护呢? 这里只说一下禁止VPN账户登录到服务器的设置,直接上图 找到权限分配后把VPN账号添加到拒绝本地登录的策略中,这样保障了VPN账户不能通过 ...

  10. 分享一个自用的 Inno Setup 软件打包脚本

    此脚本支持打包mysql.安装mysql服务.安装windows服务.操作ini文件.操作注册表.高效压缩文件等功能,基本能满足常用的软件打包需求. ;定义各种常量 #define MyAppName ...