Time Limit: 5 Sec  Memory Limit: 64 MB
Submit: 920  Solved: 569
[Submit][Status][Discuss]

Description

Ever the maturing businessman, Farmer John realizes that he must manage his time effectively. He has N jobs conveniently numbered 1..N (1 <= N <= 1,000) to accomplish (like milking the cows, cleaning the barn, mending the fences, and so on). To manage his time effectively, he has created a list of the jobs that must be finished. Job i requires a certain amount of time T_i (1 <= T_i <= 1,000) to complete and furthermore must be finished by time S_i (1 <= S_i <= 1,000,000). Farmer John starts his day at time t=0 and can only work on one job at a time until it is finished. Even a maturing businessman likes to sleep late; help Farmer John determine the latest he can start working and still finish all the jobs on time.

N个工作,每个工作其所需时间,及完成的Deadline,问要完成所有工作,最迟要什么时候开始.

Input

* Line 1: A single integer: N

* Lines 2..N+1: Line i+1 contains two space-separated integers: T_i and S_i

Output

* Line 1: The latest time Farmer John can start working or -1 if Farmer John cannot finish all the jobs on time.

Sample Input

4
3 5
8 14
5 20
1 16

INPUT DETAILS:

Farmer John has 4 jobs to do, which take 3, 8, 5, and 1 units of
time, respectively, and must be completed by time 5, 14, 20, and
16, respectively.

Sample Output

2

OUTPUT DETAILS:

Farmer John must start the first job at time 2. Then he can do
the second, fourth, and third jobs in that order to finish on time.

HINT

 

Source

Silver

二分最小开始时间

 #include <algorithm>
#include <cstdio> inline void read(int &x)
{
x=; register char ch=getchar();
for(; ch>''||ch<''; ) ch=getchar();
for(; ch>=''&&ch<=''; ch=getchar()) x=x*+ch-'';
}
const int N();
struct Work {
int t,s;
bool operator < (const Work&x)const
{
if(s==x.s) return t<x.t;
return s<x.s;
}
}job[N]; int ans=-,L,R,Mid,n;
inline bool check(int x)
{
for(int i=; i<=n; ++i)
{
if(x+job[i].t>job[i].s) return ;
x+=job[i].t;
}
return ;
} int Presist()
{
// freopen("manage.in","r",stdin);
// freopen("manage.out","w",stdout); read(n);
for(int t,i=; i<=n; ++i)
read(job[i].t),read(job[i].s);
std::sort(job+,job+n+);
for(R=job[].s-job[].t+; L<=R; )
{
Mid=L+R>>;
if(check(Mid))
{
ans=Mid;
L=Mid+;
}
else R=Mid-;
}
printf("%d\n",ans);
return ;
} int Aptal=Presist();
int main(int argc,char**argv){;}

BZOJ——1620: [Usaco2008 Nov]Time Management 时间管理的更多相关文章

  1. BZOJ 1620: [Usaco2008 Nov]Time Management 时间管理( 二分答案 )

    二分一下答案就好了... --------------------------------------------------------------------------------------- ...

  2. BZOJ 1620 [Usaco2008 Nov]Time Management 时间管理:贪心

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1620 题意: 有n个工作,每一个工作完成需要花费的时间为tim[i],完成这项工作的截止日 ...

  3. BZOJ 1620: [Usaco2008 Nov]Time Management 时间管理

    Description Ever the maturing businessman, Farmer John realizes that he must manage his time effecti ...

  4. bzoj 1620: [Usaco2008 Nov]Time Management 时间管理【贪心】

    按s从大到小排序,逆推时间模拟工作 #include<iostream> #include<cstdio> #include<algorithm> using na ...

  5. 1620: [Usaco2008 Nov]Time Management 时间管理

    1620: [Usaco2008 Nov]Time Management 时间管理 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 506  Solved: ...

  6. 【BZOJ】1620: [Usaco2008 Nov]Time Management 时间管理(贪心)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1620 一开始想不通啊.. 其实很简单... 每个时间都有个完成时间,那么我们就从最大的 完成时间的开 ...

  7. bzoj1620 [Usaco2008 Nov]Time Management 时间管理

    Description Ever the maturing businessman, Farmer John realizes that he must manage his time effecti ...

  8. BZOJ 1229: [USACO2008 Nov]toy 玩具

    BZOJ 1229: [USACO2008 Nov]toy 玩具 标签(空格分隔): OI-BZOJ OI-三分 OI-双端队列 OI-贪心 Time Limit: 10 Sec Memory Lim ...

  9. Bzoj 1229: [USACO2008 Nov]toy 玩具 题解 三分+贪心

    1229: [USACO2008 Nov]toy 玩具 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 338  Solved: 136[Submit] ...

随机推荐

  1. 《linux设备驱动开发详解》笔记——10中断与时钟

    10.1 中断与定时器 中断一般有如下类型: 内部中断和外部中断:内部中断来自CPU,例如软件中断指令.溢出.除0错误等:外部中断有外部设备触发 可屏蔽中断和不可屏蔽中断 向量中断和非向量中断,ARM ...

  2. 《零基础入门学习Python》【第一版】视频课后答案第001讲

    测试题答案: 0. Python 是什么类型的语言? Python是脚本语言 脚本语言(Scripting language)是电脑编程语言,因此也能让开发者藉以编写出让电脑听命行事的程序.以简单的方 ...

  3. 安装VS2010 无法打开数据文件deffactory.dat

    VS2010旗舰版可用Key: YCFHQ9DWCYDKV88T2TMHG7BHP 解压VS2010安装ISO文件,找到setup\deffactory.dat文件,用记事本打开,将里面内容清空,将以 ...

  4. (转)减少oracle sql回表次数 提高SQL查询性能

    要写出高效的SQL,那么必须必须得清楚SQL执行路径,介绍如何提高SQL性能的文章很多,这里不再赘述,本人来谈谈如何从 减少SQL回表次数 来提高查询性能,因为回表将导致扫描更多的数据块. 我们大家都 ...

  5. install mongodb on macos

    Update Homebrew’s package database. In a system shell, issue the following command: brew update 2 In ...

  6. 2049: [Sdoi2008]Cave 洞穴勘测(LCT)

    2049: [Sdoi2008]Cave 洞穴勘测 Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 9962  Solved: 4824[Submit] ...

  7. Python属性描述符(二)

    Python存取属性的方式特别不对等,通过实例读取属性时,通常返回的是实例中定义的属性,但如果实例未曾定义过该属性,就会获取类属性,而为实例的属性赋值时,通常会在实例中创建属性,而不会影响到类本身.这 ...

  8. python基础学习笔记——正则表达式

    1.什么是正则? 正则就是用一些具有特殊含义的符号组合到一起(称为正则表达式)来描述字符或者字符串的方法.或者说:正则就是用来描述一类事物的规则.(在Python中)它内嵌在Python中,并通过 r ...

  9. NetBeans无法使用编码GBK安全地打开该文件

    今天用NetBeans打开包含路径里面的UTF-8编码的文件时,提示:NetBeans无法使用编码GBK安全地打开该文件. 后来在网上搜索找到了解决方案,原文地址:http://qdjinxin.it ...

  10. 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 F Color it

    链接:https://www.nowcoder.com/acm/contest/163/F 来源:牛客网 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 F Color it 时间限制:C ...