VK Cup 2012 Qualification Round 1 ( E Phone Talks)
来源:互联网 发布:优秀的淘宝店铺设计 编辑:程序博客网 时间:2024/04/28 05:34
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 ti (in seconds since the start of the day) when it is scheduled to start and its duration di (in seconds). All ti 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.
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 ti and di, (1 ≤ ti, di ≤ 86400). All ti are distinct, the calls are given in the order of strict increasing ti.
Scheduled times of calls [ti, ti + di - 1] can arbitrarily intersect.
Print a number from 0 to 86400, inclusive — the maximally possible number of seconds for Mr. Jackson to sleep today.
3 230000 1500040000 1500050000 15000
49999
5 11 2000010000 1000020000 2000025000 1000080000 60000
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.
刚开始 看到这题的时候以为是贪心,只要枚举取消连续k个时间段,然后找到一个最大的值就是结果。 提交的时候发现一直过不了pretext 9,后面猜到了可能是个动态规划的。但是脑子已经打乱了。就没心思做了。
在CF上做题就是方便,做完比赛可以直接看别人代码借鉴。但是因为是看的别人的代码,肯定会缺少很多自己独立思考的过程,然后下次遇到类似的问题依旧会很难在有限的时间内解决。但是又实在想不出其他方法,可以不看别人代码而学到想要学的思想。
大神都说做动态规划要多思考。肯定是自己思考得太少了。
下面是模仿别人AC的代码:
#include<iostream>#include<windows.h>using namespace std;int t[4010],d[4010];int dp[4010][4010];int main(){int n,k,i,j,res=0;cin>>n>>k;for(i=1;i<=n;i++) cin>>t[i]>>d[i];for(i=0;i<=k;i++) dp[0][i]=1;t[n+1]=86401; d[n+1]=1;for(i=1;i<=n+1;i++)for(j=0;j<=k;j++){dp[i][j]=max(dp[i-1][j],t[i])+d[i];if(t[i]>dp[i-1][j]) res=max(res,t[i]-dp[i-1][j]); if(j>=1)dp[i][j]=min(dp[i-1][j-1],dp[i][j]);}cout<<res<<endl; return 0;}
- VK Cup 2012 Qualification Round 1 ( E Phone Talks)
- VK Cup 2012 Qualification Round 1 E. Phone Talks —— DP
- VK Cup 2012 Qualification Round 1 E
- 【dp】VK Cup 2012 Qualification Round 1 ——E
- VK Cup 2012 Qualification Round 2 E 无语凝噎
- VK Cup 2012 Qualification Round 1 A题
- VK Cup 2012 Qualification Round 1 A题解题报告
- VK Cup 2012 Qualification Round 1 B. Taxi
- VK Cup 2012 Qualification Round B题
- VK Cup 2012 Qualification Round 2部分题解(C,D,E)
- VK Cup 2012 Qualification Round 2--E. Zebra Tower 离散化+优先队列
- Codeforces VK Cup 2012 Qualification Round 1 / 158A Next Round(模拟)
- VK Cup 2012 Qualification Round 2 C. String Manipulation 1.0
- VK Cup 2015 - Qualification Round 1 B. Photo to Remember
- VK Cup 2012 Qualification Round 1--C. Cd and pwd commands
- 【优化&“调整”思想】VK Cup 2012 Qualification Round 1 / 158B Taxi(贪心)
- Codeforces VK Cup 2012 Qualification Round 1 /158C (字符串处理)
- VK Cup 2012 Qualification Round 1---C. Cd and pwd commands
- SHIFT_JIS编码无法显示全角波浪号~
- Android中ScrollView与ListView共用问题的解决方案
- Lighting sensor 工作流程
- Microsoft Access中如何获得ListBox选中的记录
- 阿里巴巴数据采集
- VK Cup 2012 Qualification Round 1 ( E Phone Talks)
- I love C++
- java连接oracle
- Eclipse右键点击run as Java Application .运行报错 Exception in thread "main"
- Java并发学习笔记(10)线程同步容器
- gdb 线程锁与non-stop模式
- 最简单的Cpp程序
- struts命名空间(basePath)(前两行<%%>不要删)(struts.xml修改以后需要重启服务器)
- 贷款证券化