Codeforces 158E Phone Talks
http://codeforces.com/contest/158/problem/E
题目大意:
麦克是个名人每天都要接n电话,每通电话给出打来的时间和持续时间,麦克可以选择接或不接,但是只能不接k通电话。如果某通电话打来时麦克正在打电话他可以选择让电话排队,或者忽略不接。当麦克空闲时首先从排队的第一个打来的电话开始接起。麦克是个很懒的人,所以需要大量的睡觉,但是睡觉的时间必须是连续的,因此要求出麦克能睡觉的最大连续时间。
思路:dp[i][j]代表前i个电话,不听j个的最少时间,然后枚举即可
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<iostream>
struct node{
int t,d;
}p[];
int n,m,f[][];
bool cmp(node a,node b){
return a.t<b.t;
}
int read(){
int t=,f=;char ch=getchar();
while (ch<''||ch>''){if (ch=='-') f=-;ch=getchar();}
while (''<=ch&&ch<=''){t=t*+ch-'';ch=getchar();}
return t*f;
}
int main(){
n=read();m=read();
for (int i=;i<n;i++) p[i].t=read(),p[i].d=read();
std::sort(p,p+n,cmp);
p[n].t=;
f[][]=;
f[][]=p[].t+p[].d-;
if (m==n){
printf("");
return ;
}
for (int i=;i<n;i++){
f[i][]=std::max(p[i].t-,f[i-][])+p[i].d;
for (int j=;j<=m&&j<=i;j++){
int xx=p[i].t-;
if (i->=j) xx=std::max(xx,f[i-][j]);
f[i][j]=std::min(f[i-][j-],xx+p[i].d);
}
}
int ans=;
for (int i=;i<n;i++)
for (int j=;j<=m;j++){
int x=std::min(n,m-j+i+);
ans=std::max(ans,p[x].t--f[i][j]);
}
printf("%d\n",ans);
return ;
}
Codeforces 158E Phone Talks的更多相关文章
- Codeforces 158E Phone Talks:dp
题目链接:http://codeforces.com/problemset/problem/158/E 题意: 你有n个电话要接,每个电话打进来的时刻为第t[i]分钟,时长为d[i]分钟. 每一个电话 ...
- codeforces E. Phone Talks(dp)
题目链接:http://codeforces.com/contest/158/problem/E 题意:给出一些电话,有打进来的时间和持续的时间,如果人在打电话,那么新打进来的电话入队,如果人没有打电 ...
- Codeforces Round #561 (Div. 2) C. A Tale of Two Lands
链接:https://codeforces.com/contest/1166/problem/C 题意: The legend of the foundation of Vectorland talk ...
- VK Cup 2012 Qualification Round 1 E. Phone Talks —— DP
题目链接:http://codeforces.com/contest/158/problem/E E. Phone Talks time limit per test 3 seconds memory ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
随机推荐
- 2016.08.13/2/index/_d_Lucene54_0.dvm: Too many open files
er[file_system_exception: /elk/elasticsearch/data/es_cluster/nodes/0/indices/logstash-zjzc-frontend- ...
- BZOJ3399: [Usaco2009 Mar]Sand Castle城堡
3399: [Usaco2009 Mar]Sand Castle城堡 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 22 Solved: 17[Sub ...
- iOS 9之New UIKit for International User Interfaces
金田 Apple一直是注重用户体验的典范,而此次在UI上面,更是做到极致.此次iOS 9的发布能完全支持阿拉伯语.希伯来语等书写和阅读方式为从右向左的语言环境.不仅仅是简单的基础文本,而是支持将界面翻 ...
- asp.net 1.1网站开发配置出现”Visual Studio .NET 无法创建或打开应用程序”解决方法
可能的解决方案: 1.注册.net framework 1.1 C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\aspnet_regiis /i 2,如果配置 ...
- HDOJ 1266 Reverse Number(数字反向输出题)
Problem Description Welcome to 2006'4 computer college programming contest! Specially, I give my bes ...
- WebApi限制IP地址请求
, ); } } } ? true : false; } ...
- Codeforces Round #203 - D. Looking for Owls
D. Looking for Owls Emperor Palpatine loves owls very much. The emperor has some blueprints with the ...
- 为什么p标签不能嵌套div??
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...
- javascript 实现分享功能
1.面向过程分享 <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...
- [转]Android 使用Scroller实现绚丽的ListView左右滑动删除Item效果
转帖请注明本文出自xiaanming的博客(http://blog.csdn.net/xiaanming/article/details/17539199),请尊重他人的辛勤劳动成果,谢谢! 我在上一 ...