Ada, Bertrand and Charles often argue over which TV shows to watch, and to avoid some of their fights they have finally decided to buy a video tape recorder. This fabulous, new device can record kk different TV shows simultaneously, and whenever a show recorded in one the machine's kk slots ends, the machine is immediately ready to record another show in the same slot.

The three friends wonder how many TV shows they can record during one day. They provide you with the TV guide for today's shows, and tell you the number of shows the machine can record simultaneously. How many shows can they record, using their recording machine? Count only shows that are recorded in their entirety.

Input Format

The first line of input contains two integers nn, kk (1 \le k < n \le 100 000)(1≤k<n≤100000). Then follow nn lines, each containing two integers x_i, y_ixi​,yi​, meaning that show ii starts at time x_ixi​ and finishes by time y_iyi​. This means that two shows iiand jj, where y_i = x_jyi​=xj​, can be recorded, without conflict, in the same recording slot. You may assume that 0 \le x_i < y_i \le 1 000 000 0000≤xi​<yi​≤1000000000.

Output Format

The output should contain exactly one line with a single integer: the maximum number of full shows from the TV guide that can be recorded with the tape recorder.

样例输入1

3 1
1 2
2 3
2 3

样例输出1

2

样例输入2

4 1
1 3
4 6
7 8
2 5

样例输出2

3

样例输入3

5 2
1 4
5 9
2 7
3 8
6 10

样例输出3

3

题目来源

Nordic Collegiate Programming Contest 2015​

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
#include <string>
#include <map>
#include <cmath>
#include <set>
#include <algorithm>
using namespace std;
const int N=1e5+;
struct Node
{
int s,e;
}node[N];
bool cmp(Node a,Node b)
{
return a.e<b.e;//按终止时间从小到大
}
int n,k;
multiset<int>se;//可以存储等值元素
/*
1 8
2 9
5 10
7 10
_____
就会有10 10 (k==2)
*/
multiset<int>::iterator it;//注意::写在前面
int main()
{
scanf("%d%d",&n,&k);
for(int i=;i<n;i++ ) scanf("%d%d",&node[i].s,&node[i].e);
sort(node,node+n,cmp);
se.clear();
for(int i=;i<k;i++) se.insert();
int ans=;
for(int i=;i<n;i++)
{
it=se.upper_bound(node[i].s);
if(it==se.begin()) continue;
it--;//第一个>node[i].s的数的前面的数一定是小于node[i].sb_type
// 并且一定是和node[i].s的差值最小的(贪心),把更早结束的留给开始时间比较小的
se.erase(it);//播放完了,就要更新掉/
se.insert(node[i].e);
ans++;
}
printf("%d\n",ans);
return ;
}

Nordic Collegiate Programming Contest 2015​ E. Entertainment Box的更多相关文章

  1. 2015-2016 ACM-ICPC Nordic Collegiate Programming Contest ---E题Entertainment Box(有点变化的贪心)

    提交链接 http://codeforces.com/gym/100781/submit Description: Ada, Bertrand and Charles often argue over ...

  2. Nordic Collegiate Programming Contest 2015​ B. Bell Ringing

    Method ringing is used to ring bells in churches, particularly in England. Suppose there are 6 bells ...

  3. Nordic Collegiate Programming Contest 2015​ G. Goblin Garden Guards

    In an unprecedented turn of events, goblins recently launched an invasion against the Nedewsian city ...

  4. Nordic Collegiate Programming Contest 2015​ D. Disastrous Downtime

    You're investigating what happened when one of your computer systems recently broke down. So far you ...

  5. Nordic Collegiate Programming Contest 2015​(第七场)

    A:Adjoin the Networks One day your boss explains to you that he has a bunch of computer networks tha ...

  6. (寒假GYM开黑)2018-2019 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2018)

    layout: post title: 2018-2019 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2018) author: &qu ...

  7. German Collegiate Programming Contest 2015 计蒜课

    // Change of Scenery 1 #include <iostream> #include <cstdio> #include <algorithm> ...

  8. Codeforces Gym101572 B.Best Relay Team (2017-2018 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2017))

    2017-2018 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2017) 今日份的训练,题目难度4颗星,心态被打崩了,会的算法太少了,知 ...

  9. 2018-2019 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2018)- D. Delivery Delays -二分+最短路+枚举

    2018-2019 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2018)- D. Delivery Delays -二分+最短路+枚举 ...

随机推荐

  1. 树莓派连接启动SSH

    树莓派的官方更新消息发布:http://downloads.raspberrypi.org/raspbian/release_notes.txt SSH禁用的启用方法: 2016年11月25日: * ...

  2. 整理一些最近项目中用到的一些JS方法

    验证是否为图片格式 function IsImgType(src) { var rFilter = /^(?:image\/bmp|image\/cis\-cod|image\/gif|image\/ ...

  3. P4869 罪犯分组

    思路: 明显的dp,虽然我想到了二进制模拟,想到了转移,但还是先看了题解,原来真是这样,,,,不是第三题吗? 用f[i]表示,对于前i个罪犯最少需要分几组. 对于每个状态用二进制表示,第i位上1,0表 ...

  4. feign实现服务间的负载均衡

    feign Feign是一个声明式的Web Service客户端,它使得编写Web Serivce客户端变得更加简单.我们只需要使用Feign来创建一个接口并用注解来配置它既可完成.它具备可插拔的注解 ...

  5. 工作方法-scrum+番茄工作法

    1.产品和开发团队近期的工作分析和安排,使用scrum. 产品的工作:通过product backlog来列出 开发团队近期的工作安排:通过sprint backlog来列出,由个人认领,并估算(优先 ...

  6. vmware 虚机NAT模式,局域网可访问

    本地VMware虚拟机,网络模式为NAT,现在需要局域网其他电脑通过ssh连接这台VMware虚拟机 宿主机地址:192.168.3.26 VMware虚拟机地址:192.168.239.137 局域 ...

  7. UVA 1149 Bin Packing 装箱(贪心)

    每次选最大的物品和最小的物品放一起,如果放不下,大物体孤独终生,否则相伴而行... 答案变得更优是因为两个物品一起放了,最大的物品是最难匹配的,如果和最小的都放不下的话,和其它匹配也一定放不下了. # ...

  8. vue 修改端口

  9. 用python Image读图

    https://www.cnblogs.com/kongzhagen/p/6295925.html import os name = [] with open('/media/hdc/xing/Dee ...

  10. SQLServer锁原理和锁的类型

    1.锁的用途 为了避免同时争夺数据库资源,将数据库加锁,只有拿到钥匙的用户才能使用: 2.锁的粒度 行锁(Row)--->页锁(Page)--->区锁(Partition 8个页)---- ...