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 ;
}

最新文章

  1. 第二天--html
  2. Editplus配置VC++(2) 与/d1reportSingleClassLayout
  3. 其他信息: 未找到源,不过,未能搜索部分或所有事件日志。 若要创建源,您需要用于读取所有事件日志的权限以确保新的源名称是唯一的。 不可访问的日志: Security。
  4. Java基础语法目录
  5. 几个开源XMPP Android客户端简单比较
  6. Android TextView走马灯效果
  7. javascript library
  8. 剑指Offer01 杨氏数组寻值
  9. 更改Activity亮度
  10. makefile使用
  11. [iOS基础控件 - 6.10.4] 项目启动原理 项目中的文件
  12. 乐视mysql面试题
  13. python 初学习 模拟用户登录
  14. HTTP报错401和403详解及解决办法
  15. ubuntu16.04 使用kinectv2跑Elasticfusion
  16. Date.parse()转化日期为时间戳,ios与Android兼容写法
  17. Wijmo 2017路线图
  18. 20155325 Exp6 信息搜集与漏洞扫描
  19. Appium Desktop介绍-xcodebuild failed with code 65 问题解决
  20. TSQL--TOP选项

热门文章

  1. 《深入理解java虚拟机》笔记(2)HotSpot虚拟机对象探秘
  2. Centos安装TensorFlow和Keras
  3. 5.类型、值和变量-JavaScript权威指南笔记
  4. 洛谷 P1202 [USACO1.1]黑色星期五Friday the Thirteenth
  5. Nmap安全扫描程序
  6. Appium基础四:Desired Capabilities详讲
  7. 【js类库AngularJs】解决angular+springmvc的post提交问题
  8. css隐藏元素的几种方法与区别
  9. C#字段声明部分如何调用该类中的方法进行初始化?
  10. 【虚拟机-部署】通过 Powershell 来调整 ARM 模式下虚拟机的尺寸