http://codeforces.com/contest/158/problem/E

题目大意:

麦克是个名人每天都要接n电话,每通电话给出打来的时间和持续时间,麦克可以选择接或不接,但是只能不接k通电话。如果某通电话打来时麦克正在打电话他可以选择让电话排队,或者忽略不接。当麦克空闲时首先从排队的第一个打来的电话开始接起。麦克是个很懒的人,所以需要大量的睡觉,但是睡觉的时间必须是连续的,因此要求出麦克能睡觉的最大连续时间。

思路:dp[i][j]代表前i个电话,不听j个的最少时间,然后枚举即可

  1. #include<cstdio>
  2. #include<cmath>
  3. #include<algorithm>
  4. #include<cstring>
  5. #include<iostream>
  6. struct node{
  7. int t,d;
  8. }p[];
  9. int n,m,f[][];
  10. bool cmp(node a,node b){
  11. return a.t<b.t;
  12. }
  13. int read(){
  14. int t=,f=;char ch=getchar();
  15. while (ch<''||ch>''){if (ch=='-') f=-;ch=getchar();}
  16. while (''<=ch&&ch<=''){t=t*+ch-'';ch=getchar();}
  17. return t*f;
  18. }
  19. int main(){
  20. n=read();m=read();
  21. for (int i=;i<n;i++) p[i].t=read(),p[i].d=read();
  22. std::sort(p,p+n,cmp);
  23. p[n].t=;
  24. f[][]=;
  25. f[][]=p[].t+p[].d-;
  26. if (m==n){
  27. printf("");
  28. return ;
  29. }
  30. for (int i=;i<n;i++){
  31. f[i][]=std::max(p[i].t-,f[i-][])+p[i].d;
  32. for (int j=;j<=m&&j<=i;j++){
  33. int xx=p[i].t-;
  34. if (i->=j) xx=std::max(xx,f[i-][j]);
  35. f[i][j]=std::min(f[i-][j-],xx+p[i].d);
  36. }
  37. }
  38. int ans=;
  39. for (int i=;i<n;i++)
  40. for (int j=;j<=m;j++){
  41. int x=std::min(n,m-j+i+);
  42. ans=std::max(ans,p[x].t--f[i][j]);
  43. }
  44. printf("%d\n",ans);
  45. return ;
  46. }

Codeforces 158E Phone Talks的更多相关文章

  1. Codeforces 158E Phone Talks:dp

    题目链接:http://codeforces.com/problemset/problem/158/E 题意: 你有n个电话要接,每个电话打进来的时刻为第t[i]分钟,时长为d[i]分钟. 每一个电话 ...

  2. codeforces E. Phone Talks(dp)

    题目链接:http://codeforces.com/contest/158/problem/E 题意:给出一些电话,有打进来的时间和持续的时间,如果人在打电话,那么新打进来的电话入队,如果人没有打电 ...

  3. 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 ...

  4. 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 ...

  5. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  6. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  7. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  8. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  9. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

随机推荐

  1. jsonp实现跨域资源访问

    平时项目中处理ajax跨域资源请求时,例如www.example2.com上的某个页面要请求www.example1.com的数据,我们使用得较多的是jsonp方式.jsonp通过JavaScript ...

  2. HDOJ 1303 Doubles(简单题)

    Problem Description As part of an arithmetic competency program, your students will be given randoml ...

  3. MD中bitmap源代码分析--入题概述

    在MD模块中,各级raid都使用的一份bitmap的源码,也就是说共用一种bitmap的流程,下面以raid1的使用为例来分析bitmap的工作原理. 在使用raid1磁盘阵列的时候,对于数据的可靠性 ...

  4. java随机数生成器

    一.java.lang.Math.Random 调用这个Math.Random()函数能够返回带正号的double值,取值范围是[0.0,1.0)的左闭右开区间,并在该范围内(近似)均匀分布. 二.j ...

  5. css样式-表格优化

    1.表格的初步优化 index.html <!DOCTYPE html> <html> <head> <meta charset="UTF-8&qu ...

  6. css3 渐变linear-gradient

    background: -moz-linear-gradient(top, #FC641C, #FC761C); 参数:其共有三个参数,第一个参数表示线性渐变的方向,top 是从上到下.left 是从 ...

  7. (转)关于Android的nodpi,xhdpi,hdpi,mdpi,ldpi

    首先是几个基本概念:1.屏幕尺寸Screen size即显示屏幕的实际大小,按照屏幕的对角线进行测量.为简单起见,Android把所有的屏幕大小分为四种尺寸:小,普通,大,超大(分别对应:small, ...

  8. 关于kendo ui的使用改变颜色方式

    1.概述: 在网上kendo ui教程中示例在演示的时候引用的css样式为kendo.common.min.css与kendo.default.min.css这两个外部样式,大家有没有发现,这两个样式 ...

  9. ACtivity实现欢迎界面并添加动画切换效果

    先看效果: 中间切换动画没来得及截图,凑合着看吧. 主要是java代码的实现: Welcom.java package kehr.activity.welcome; import android.ap ...

  10. POJ 2502 Subway(迪杰斯特拉)

    Subway Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6692   Accepted: 2177 Descriptio ...