题目描述

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工作要 做,比如给奶牛挤奶,清洗牛棚,修理栅栏之类的.

为了高效,列出了所有工作的清单.第i分工作需要T_i单位的时间来完成,而 且必须在S_i或之前完成.现在是0时刻.约翰做一份工作必须直到做完才能停 止.

所有的商人都喜欢睡懒觉.请帮约翰计算他最迟什么时候开始工作,可以让所有工作按时完 成.

输入输出格式

输入格式:

  • Line 1: A single integer: N

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

输出格式:

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

输入输出样例

输入样例#1:
复制

4
3 5
8 14
5 20
1 16
输出样例#1: 复制

2

说明

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.

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.

思路

以时间限制s为关键字从大到小排序,贪心选取;

代码

 #include<cstdio>
#include<algorithm>
using namespace std;
const int maxn=1e3+;
inline int min_(int x,int y){return x<y?x:y;}
int n,ans=1e6;
struct nate{int t,s;}s[maxn];
bool comp(nate x,nate y){return x.s>y.s;}
int main(){
scanf("%d",&n);
for(int i=;i<=n;i++) scanf("%d%d",&s[i].t,&s[i].s);
sort(s+,s+n+,comp);
for(int i=,j=1e6;i<=n;i++) ans=min_(ans,s[i].s)-s[i].t;
if(ans>=) printf("%d\n",ans);
else puts("-1");
return ;
}

[USACO08NOV]时间管理Time Management的更多相关文章

  1. bzoj1620 / P2920 [USACO08NOV]时间管理Time Management

    P2920 [USACO08NOV]时间管理Time Management 显然的贪心. 按deadline从大到小排序,然后依次填充时间. 最后时间为负的话那么就是无解 #include<io ...

  2. P2920 [USACO08NOV]时间管理Time Management

    P2920 [USACO08NOV]时间管理Time Management 题目描述 Ever the maturing businessman, Farmer John realizes that ...

  3. 题解 P2920 【[USACO08NOV]时间管理Time Management】

    题面 作为一名忙碌的商人,约翰知道必须高效地安排他的时间.他有N工作要 做,比如给奶牛挤奶,清洗牛棚,修理栅栏之类的. 为了高效,列出了所有工作的清单.第i分工作需要T_i单位的时间来完成,而 且必须 ...

  4. 洛谷 P2920 [USACO08NOV]时间管理Time Management

    传送门 题目大意: 每个工作有截至时间和耗费时间,n个工作求最小开始时间. 题解: 贪心 从n-1安排,让结束时间尽量的晚. 注意:优先级 cout<<st<0?-1:st;  (X ...

  5. [USACO08NOV]时间管理Time Management(排序,贪心)

    题目描述 作为一名忙碌的商人,约翰知道必须高效地安排他的时间.他有N工作要 做,比如给奶牛挤奶,清洗牛棚,修理栅栏之类的. 为了高效,列出了所有工作的清单.第i分工作需要T_i单位的时间来完成,而 且 ...

  6. [LUOGU] P2920 [USACO08NOV]时间管理Time Management

    见7.3测试 #include<iostream> #include<algorithm> #include<cstdio> using namespace std ...

  7. CMSIS-RTOS 时间管理之时间延迟Time Delay

    时间管理 Time Management 此RTOS除了可以把你的应用代码作为线程运行,它还可以提供一些时间服务功能,使用这些功能你就可以访问RTOS的一些系统调用. 时间延迟Time Delay 在 ...

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

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

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

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

随机推荐

  1. 窗口Dialog

    Dialog是窗口的意思,它是Window的子类.与frame相比,frame是我们大的窗口,而dialog便是那种弹出来和你说话的对话框. Dialog类的默认布局是BorderLayout Dia ...

  2. cloudera-scm-server启动出现Error creating bean with name 'entityManagerFactoryBean'与HHH010003: JDBC Driver class not found: com.mysql.jdbc.Driver错误解决办法(图文详解)

    不多说,直接上干货! 问题详情 -- ::, INFO main:com.cloudera.server.cmf.Main: Starting SCM Server. JVM Args: [-Dlog ...

  3. Kali linux 2016.2(Rolling)里安装中文输入法

    写在前面的话 关于中文输入法,实在是有太多了.当然,你也不可以不安装,(安装了增强工具即可),在windows 里输入中文,复制进去即可. 但是呢,想成为高手,还是要学会安装和使用各版本的中文输入法. ...

  4. java IO流 复制图片

    (一)使用字节流复制图片 //字节流方法 public static void copyFile()throws IOException { //1.获取目标路径 //(1)可以通过字符串 // St ...

  5. java数据结构和算法04(链表)

    前面我们看了数组,栈和队列,大概就会这些数据结构有了一些基本的认识,首先回顾一下之前的东西: 在数组中,其实是分为有序数组和无序数组,我简单实现了无序数组,为什么呢?因为有序数组的实现就是将无序数组进 ...

  6. iOS Programming NSUserDefaults

    iOS Programming NSUserDefaults  When you start an app for the first time, it uses its factory settin ...

  7. iisexpress局域网内调试网站

    1.找到IISExpress目录 IISExpress\config\applicationhost.config(注:如果使用vs2015则更改解决方案目录下的.vs文件夹中的该文件) <si ...

  8. ZooKeeper系列(二)

    Zookeeper的环境配置 一.Zookeeper的搭建方式 Zookeeper安装方式有三种,单机模式和集群模式以及伪集群模式. 1.单机模式:Zookeeper只运行在一台服务器上,适合测试环境 ...

  9. 在DOS行下设置静态IP

    A.设置静态IP  CMD  netsh  netsh>int  interface>ip  interface ip>set add "本地链接" static ...

  10. xamarin.forms 绑定页面里指定元素的某个属性值

    {Binding Source={x:Reference elementName}, Path=BindingContext.propertyname, Mode=OneWay} elementNam ...