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. 用 HTML5 造个有诚意的 23D 招聘稿

    前言 招聘对于一个公司来说是相当重要的一个环节,首先它影响着公司未来发展的趋势,其次它为公司注入新鲜血液,使公司更具有活力.当然在工业互联网,物联网大背景下诞生的 HT 也是需要注入新鲜的血液来进一步 ...

  2. 如何把.a转化为framework

    在Xcode中,framework比分散的.a和.h文件用起来方便的多.然而,只要你一找如何制作framework,多半你就会放弃,“怎么这么麻烦?!” 尤其是当已经有现成的.a和.h时,你就会更不能 ...

  3. iview中遇到table的坑(已经修改了table的数据,但是界面没有更新)

    https://blog.csdn.net/bigdargon/article/details/89381466 https://blog.csdn.net/qiuyan_f/article/deta ...

  4. AppBoxFuture实战: 如何同步开发与生产环境的模型

      框架是用抽象模型驱动的方式来生成应用系统的,这样可以将这些模型序列化为相应的模型包文件,通过反序列化导入至其他部署环境内,从而实现开发环境与生产环境的同步,包括对应的数据库结构的同步.下面通过示例 ...

  5. 高可用Keepalived+LVS搭建流程

    本流程搭建1个master,1个backup节点的Keepalived,使用lvs轮询2个节点的服务. 一.使用版本 CentOS 7.7 Keepalived 1.3.5 ipvsadm 1.27( ...

  6. 【PG】Greenplum-db-6.2.1的安装部署

    目录 1配置host文件(所有节点) 2 配置用户 3 配置/etc/sysctl.conf文件 4 limit文件,后面添加[不影响安装] 5 安装greenplum-db-6.2.1-rhel7- ...

  7. 03、MySql的数据类型

    MySQL中定义数据字段的类型对你数据库的优化是非常重要的. MySQL支持多种类型,大致可以分为三类:数值.日期/时间和字符串(字符)类型. 1.数字类型 类型 大小 范围(有符号) 范围(无符号) ...

  8. html 5 cavans 简易祖玛

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  9. 解决 微信包含emoji表情的昵称,直接用sql语句可以写入而在yii2框架写却写不成功的 问题

    背景: 首先是emoji表情写入不成功,在网上查了许多资料,包括配置mysql,重启mysql等等,这样之后发现还是写入失败. 将sql语句复制出来,直接粘贴到mysql客户端执行,发现没问题.而通过 ...

  10. nlogn的最长不下降子序列【tyvj1254挑选士兵】

    var a,d:Array[-..]of longint; i,n,m,k,l:longint; function erfen(x:longint):longint; var mid,h,t:long ...