A8408 | Phone Talks
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Cool J has recently become a businessman Mr. Jackson, and he has to make a lot of phone calls now. Today he has $n$ calls planned. For each call we know the moment $t_{i}$ (in seconds since the start of the day) when it is scheduled to start and its duration $d_{i}$ (in seconds). All $t_{i}$ are different. Mr. Jackson is a very important person, so he never dials anybody himself, all calls will be incoming.
Mr. Jackson isn't Caesar and he can't do several things at once. If somebody calls him while he hasn't finished the previous conversation, Mr. Jackson puts the new call on hold in the queue. In this case immediately after the end of the current call Mr. Jackson takes the earliest incoming call from the queue and starts the conversation. If Mr. Jackson started the call at the second $t$ , and the call continues for $d$ seconds, then Mr. Jackson is busy at seconds $t,t+1,...,t+d-1$ , and he can start a new call at second $t+d$ . Note that if Mr. Jackson is not busy talking when somebody calls, he can't put this call on hold.
Mr. Jackson isn't Napoleon either, he likes to sleep. So sometimes he allows himself the luxury of ignoring a call, as if it never was scheduled. He can ignore at most $k$ calls. Note that a call which comes while he is busy talking can be ignored as well.
What is the maximum number of seconds Mr. Jackson can sleep today, assuming that he can choose an arbitrary continuous time segment from the current day (that is, with seconds from the 1-st to the 86400-th, inclusive) when he is not busy talking?
Note that some calls can be continued or postponed to the next day or even later. However, the interval for sleep should be completely within the current day.
Mr. Jackson isn't Caesar and he can't do several things at once. If somebody calls him while he hasn't finished the previous conversation, Mr. Jackson puts the new call on hold in the queue. In this case immediately after the end of the current call Mr. Jackson takes the earliest incoming call from the queue and starts the conversation. If Mr. Jackson started the call at the second $t$ , and the call continues for $d$ seconds, then Mr. Jackson is busy at seconds $t,t+1,...,t+d-1$ , and he can start a new call at second $t+d$ . Note that if Mr. Jackson is not busy talking when somebody calls, he can't put this call on hold.
Mr. Jackson isn't Napoleon either, he likes to sleep. So sometimes he allows himself the luxury of ignoring a call, as if it never was scheduled. He can ignore at most $k$ calls. Note that a call which comes while he is busy talking can be ignored as well.
What is the maximum number of seconds Mr. Jackson can sleep today, assuming that he can choose an arbitrary continuous time segment from the current day (that is, with seconds from the 1-st to the 86400-th, inclusive) when he is not busy talking?
Note that some calls can be continued or postponed to the next day or even later. However, the interval for sleep should be completely within the current day.
输入格式
The first input line contains a pair of integers $n$ , $k$ ( $0<=k<=n<=4000$ ) separated by a space. Following $n$ lines contain the description of calls for today. The description of each call is located on the single line and consists of two space-separated integers $t_{i}$ and $d_{i}$ , ( $1<=t_{i},d_{i}<=86400$ ). All $t_{i}$ are distinct, the calls are given in the order of strict increasing $t_{i}$ .
Scheduled times of calls \[ $t_{i}$ , $t_{i}+d_{i}-1$ \] can arbitrarily intersect.
Scheduled times of calls \[ $t_{i}$ , $t_{i}+d_{i}-1$ \] can arbitrarily intersect.
输出格式
Print a number from 0 to 86400, inclusive — the maximally possible number of seconds for Mr. Jackson to sleep today.
输入输出样例
输入 #1
3 2 30000 15000 40000 15000 50000 15000
输出 #1
49999
输入 #2
5 1 1 20000 10000 10000 20000 20000 25000 10000 80000 60000
输出 #2
39999
In the first sample the most convenient way is to ignore the first two calls.
In the second sample it is best to ignore the third call. In this case Mr. Jackson will have been speaking:
- first call: from 1-st to 20000-th second,
- second call: from 20001-st to 30000-th second,
- fourth call: from 30001-st to 40000-th second (the third call is ignored),
- fifth call: from 80000-th to 139999-th second.
Thus, the longest period of free time is from the 40001-th to the 79999-th second.
In the second sample it is best to ignore the third call. In this case Mr. Jackson will have been speaking:
- first call: from 1-st to 20000-th second,
- second call: from 20001-st to 30000-th second,
- fourth call: from 30001-st to 40000-th second (the third call is ignored),
- fifth call: from 80000-th to 139999-th second.
Thus, the longest period of free time is from the 40001-th to the 79999-th second.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted