题目描述

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为关键字从大到小排序,贪心选取;

代码

 1 #include<cstdio>
 2 #include<algorithm>
 3 using namespace std;
 4 const int maxn=1e3+10;
 5 inline int min_(int x,int y){return x<y?x:y;}
 6 int n,ans=1e6;
 7 struct nate{int t,s;}s[maxn];
 8 bool comp(nate x,nate y){return x.s>y.s;}
 9 int main(){
10     scanf("%d",&n);
11     for(int i=1;i<=n;i++) scanf("%d%d",&s[i].t,&s[i].s);
12     sort(s+1,s+n+1,comp);
13     for(int i=1,j=1e6;i<=n;i++) ans=min_(ans,s[i].s)-s[i].t;
14     if(ans>=0) printf("%d\n",ans);
15     else puts("-1");
16     return 0;
17 }

转载于:https://www.cnblogs.com/J-william/p/7725793.html

[USACO08NOV]时间管理Time Management相关推荐

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

    时间管理Time Management 二分枚举开始时间. #include <iostream> #include <cstdio> #include <algorit ...

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

    题目描述 Ever the maturing businessman, Farmer John realizes that he must manage his time effectively. H ...

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

    好了,废话不多说,我们切入正题,首先,不懂得分治的可以去看这位大佬的文章, 这道题是让我们求最晚可以在什么时间起床,这里我们需要加入一个小小的贪心,就是结束时间短的放前面处理,至于为什么,相信你肯定能 ...

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

    这个题不难,但我是蒟蒻... 先看题目 题目: Ever the maturing businessman, Farmer John realizes that he must manage his ...

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

    emm贪心题,但不知道怎么让我搞成了并查集 先将数组按结束时间排序,因为肯定先安排靠后的工作,后面处理时冲突会减小很多 然后如何并查集乱搞呢? 假如下图是一个没有加入任务的时间线{{20,5},{15 ...

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

    题目描述 Ever the maturing businessman, Farmer John realizes that he must manage his time effectively. H ...

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

    1620: [Usaco2008 Nov]Time Management 时间管理 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 850  Solved ...

  8. bzoj 1620: [Usaco2008 Nov]Time Management 时间管理(贪心)

    1620: [Usaco2008 Nov]Time Management 时间管理 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 834  Solved ...

  9. Time Management 时间管理

    Time Management 时间管理 世界上最快而又最慢,最长而又最短,最平凡而又最珍贵,最易被忽视而又最令人后悔的是什么? ------时间 ------接下来敢不敢完成挑战测试:你对时间的感知 ...

最新文章

  1. STK 卫星覆盖分析笔记
  2. day4(定义类,公有,私有方法,静态方法,原形方式的属性和方法)
  3. Android:dagger2让你爱不释手-基础依赖注入框架篇
  4. 解决linux ssh客户端SSH连接linux服务器很慢的问题
  5. .net里鼠标选中的text数据怎么获取_数据快速对比,这个快捷键你都不会,难怪要加班...
  6. 揭秘成为最牛程序员的五大要诀
  7. ThinkpadT470接通电源开机显示电量0%充不进电且电源指示灯不亮的解决办法
  8. uniapp监听PDA激光扫描
  9. 非法关机linux分辨率丢失,非法关机造成文件系统损坏,怎么办?请教:附图片...
  10. 翻书插件:bookblock.js
  11. JSP项目实训-Ajax聊天室
  12. 数据库原理课程设计---停车场管理系统
  13. rm mysql 数据日志文件恢复
  14. 实现原理 扫描枪_详细介绍扫描枪工作原理
  15. 完全java实现一款开源的报表工具简表(JOR)
  16. 加息对银行股影响|加息是对银行股的利好
  17. ORA12514问题
  18. LaTeX字符加的各种帽子
  19. 小型的代码管理仓库Gitea安装指南
  20. RAID——独立冗余磁盘阵列

热门文章

  1. 关于mysql叙述中错误的是什么_以下关于MySQL的叙述中,错误的是( )。_学小易找答案...
  2. mysql批量插入跟更新_Mysql批量插入和更新的性能-问答-阿里云开发者社区-阿里云...
  3. mysql单表约束为_MySQL 表约束
  4. 模型集成 | 14款常规机器学习 + 加权平均模型融合
  5. Centos7 安装X2goSever的步骤
  6. Windows下调试hadoop
  7. Dubbo zookeeper 初探【转】
  8. linux 查找并删除
  9. jquery 甘特图开发指南
  10. 计算DataTable某列的值(SUM)