D - 淡黄的长裙 HDU - 4221(贪心)

James is almost mad! Currently, he was assigned a lot of works to do,

so many that you can't imagine. Each task costs Ai time as least, and

the worst news is, he must do this work no later than time Bi!

OMG, how could it be conceivable! After simple estimation, he

discovers a fact that if a work is finished after Bi, says Ti, he will

get a penalty Ti - Bi. Though it may be impossible for him to finish

every task before its deadline, he wants the maximum penalty of all

the tasks to be as small as possible. He can finish those tasks at any

order, and once a task begins, it can't be interrupted. All tasks

should begin at integral times, and time begins from 0. Input The

first line contains a single integer T, indicating the number of test

cases. Each test case includes an integer N. Then N lines following,

each line contains two integers Ai and Bi.

Technical Specification

  1. 1 <= T <= 100
  2. 1 <= N <= 100 000
  3. 1 <= Ai, Bi <= 1 000 000 000 Output For each test case, output the case number first, then the smallest maximum penalty.
Sample Input
2
2
3 4
2 2
4
3 6
2 7
4 5
3 9
Sample Output
Case 1: 1
Case 2: 3

思路

  • 贪心 + 结构排序

代码

#include<iostream>
#include<cmath>
#include<cstdio>
#include<queue>
#include<cstring>
#include<algorithm>
#define ll long long
#define inf 0x3f3f3f3f
using namespace std; const int Len = 100005;
struct Node
{
ll s, e;
bool operator < (const Node b) const
{
if(e == b.e)
return s < b.s;
return e < b.e;
}
} node[Len]; int main()
{
/* freopen("A.txt","r",stdin); */
int t, Case = 1;
scanf("%d", &t);
while(t --)
{
ll n;
scanf("%lld", &n);
for(int i = 1; i <= n; i ++)
scanf("%lld %lld", &node[i].s, &node[i].e);
sort(node + 1, node + 1 + n);
ll ans = 0;
ll sum = 0; for(int i = 1; i <= n; i ++)
{
sum += node[i].s;
if(sum > node[i].e)
ans = max(ans, sum - node[i].e);
}
printf("Case %d: %lld\n", Case ++, ans);
} return 0;
}

D - 淡黄的长裙 HDU - 4221(贪心)的更多相关文章

  1. HDU - 4221 贪心

    题意: 你有n个任务,每一个任务有一个完成所需时间AI,和一个截止时间BI.时间从0开始,如果完成任务的时间(设这个时间为ans)大于BI那么就会收到ans-BI的惩罚,问你完成所有这些任务你会收到的 ...

  2. Hdu 5289-Assignment 贪心,ST表

    题目: http://acm.hdu.edu.cn/showproblem.php?pid=5289 Assignment Time Limit: 4000/2000 MS (Java/Others) ...

  3. hdu 4803 贪心/思维题

    http://acm.hdu.edu.cn/showproblem.php?pid=4803 话说C++还卡精度么?  G++  AC  C++ WA 我自己的贪心策略错了 -- 就是尽量下键,然后上 ...

  4. hdu 1735(贪心) 统计字数

    戳我穿越:http://acm.hdu.edu.cn/showproblem.php?pid=1735 对于贪心,二分,枚举等基础一定要掌握的很牢,要一步一个脚印走踏实 这是道贪心的题目,要有贪心的意 ...

  5. hdu 4974 贪心

    http://acm.hdu.edu.cn/showproblem.php?pid=4974 n个人进行选秀,有一个人做裁判,每次有两人进行对决,裁判可以选择为两人打分,可以同时加上1分,或者单独为一 ...

  6. hdu 4982 贪心构造序列

    http://acm.hdu.edu.cn/showproblem.php?pid=4982 给定n和k,求一个包含k个不相同正整数的集合,要求元素之和为n,并且其中k-1的元素的和为完全平方数 枚举 ...

  7. HDU 2307 贪心之活动安排问题

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2037 今年暑假不AC Time Limit: 2000/1000 MS (Java/Others)  ...

  8. HDU 1052 贪心+dp

    http://acm.hdu.edu.cn/showproblem.php?pid=1052 Tian Ji -- The Horse Racing Time Limit: 2000/1000 MS ...

  9. HDU 2111 Saving HDU【贪心】

    解题思路:排序后贪心,和fatmouse's  trade 类似 Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: ...

随机推荐

  1. 移动webApp必备技能一、WebApp 里Meta标签大全,webappmeta标签大全

    1.先说说mate标签里的viewport: viewport即可视区域,对于桌面浏览器而言,viewport指的就是除去所有工具栏.状态栏.滚动条等等之后用于看网页的区域.对于传统WEB页面来说,9 ...

  2. HDFS NameNode详解

    1. namenode介绍 namenode管理文件系统的命名空间.它维护着文件系统树及整棵树内所有的文件和目录.这些信息以两个文件形式永久保存在本地磁盘上:命名空间镜像文件fsimage和编辑日志文 ...

  3. 【Vue】---- 手动封装on,emit,off

    一.概念 1. $on("事件名称",回调函数) 事件绑定,一个事件名称上面可能绑定多个函数 2. $emit("事件名称",需要传递的值) 事件触发时,会触发 ...

  4. Vue2.0 【第一季】第8节 v-pre & v-cloak & v-once

    目录 Vue2.0 [第一季] 第8节 v-pre & v-cloak & v-once v-pre 指令 v-cloak 指令 v-once 指令 Vue2.0 [第一季] 第8节 ...

  5. Python——项目-小游戏

    开始我们的项目 飞机大战 1 项目的初体验 以及前期准备 游戏初体验画面 验证一下本地第三方包有没有导入 python3 -m pygame.examples.aliens 如果没有出现游戏画面请先安 ...

  6. python基础学习day7

    基础数据类型的补充:编码的进阶 str capitalize() 首字母(第一个单词)大写,其余变小写 s1 = 'I LIVE YOU' print(s1.capitalize()) >> ...

  7. 【题解】NOIP 2015 子串

    淦!这题我做了三个月啊 题目描述 有两个仅包含小写英文字母的字符串 \(A\) 和 \(B\). 现在要从字符串 \(A\) 中取出 \(k\) 个互不重叠的非空子串,然后把这 \(k\) 个子串按照 ...

  8. go例子(三) 使用context实现发牌手策略

    使用context包实现发牌手策略, 发牌手策略:罗永浩在介绍TNT工作站时描述,将一个任务分发给多个处理者处理,谁先处理完使用谁的结果,取消其他的处理者的任务. 经典的例子:同时在百度.google ...

  9. 集群搭建_02_集群多机版安装 HDFS HA+Federation-YARN

    1.配置hosts 至少四个节点(机器) 每个节点的hosts文件都要配置这些 10.10.64.226 SY-0217 10.10.64.234 SY-0225 10.10.64.235 SY-02 ...

  10. 在Centos系统中基于PowerDNS实现master和slave的域名解析服务双备份

    在上一篇文章中,阐述了如何在Centos 7系统(其他版本的Centos未尝试)中基于PowerDNS和poweradmin自建域名解析服务器替代DnsPod的过程.但是在一般的DNS服务中,我们需要 ...