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的更多相关文章

  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. JDBC连接mysql编程

    基本操作 package jdbc; import java.sql.Statement; import java.util.Scanner; import java.sql.Connection; ...

  2. libvirt-adabddad

    kvm i686  libvirtError: internal error cannot load AppArmor profile 'libvirt-adabddad-35ba-b9ca-e250 ...

  3. 转:史上最全最强SpringMVC详细示例实战教程

    一.SpringMVC基础入门,创建一个HelloWorld程序 1.首先,导入SpringMVC需要的jar包. 2.添加Web.xml配置文件中关于SpringMVC的配置 <!--conf ...

  4. 自定义枚举类型的常用操作-附源码(xjl456852原创)

    自定义枚举类型中,假如我们有name和desc这样的属性,并在这个基础上定义了多个对象. 那么就可能用到通过name获取desc,或者通过desc获取name.通过name或者desc获取对应的枚举对 ...

  5. linux 远程自动登录脚本 (注test.exp)

    #! /usr/bin/expect set timeout 30spawn ssh -l root 192.168.239.148 expect "password:"send ...

  6. C#文件的拆分与合并操作示例

    C#文件的拆分与合并操作示例代码. 全局变量定义 ;//文件大小 //拆分.合并的文件数 int count; FileInfo splitFile; string splitFliePath; Fi ...

  7. Win32<CreatFile>

    CreateFile函数详解 CreateFile The CreateFile function creates or opens the following objects and returns ...

  8. ubuntu server 14.04.4 无线网卡没有启用,找不到wlan0端口

    Ubuntu Server默认的情况下是不会启用无线网卡的,想想实际服务器上怎么可能有无线网卡呢,呵呵.所以我们需要手动来启用无线网卡,难点就在这里了. 使用ifconfig命令,发现没有wlan口, ...

  9. asp.net 5.0微信支付

    (原文出自:http://lib.csdn.net/article/wechat/46329) 微信支付官方坑太多,我们来精简 我把官方的代码,打包成了 an.wxapi.dll. 里面主要替换了下注 ...

  10. MySql 1045错误

    配置时以管理员身份运行MySQL Instance Configuration Wizard 当你登录MySQL数据库出现:Error 1045错误时(如下图),就表明你输入的用户名或密码错误被拒绝访 ...