Description

A restaurant received n orders for the rental. Each rental order reserve the restaurant for a continuous period of time, the i-th order is characterized by two time values — the start time li and the finish time ri (li ≤ ri).

Restaurant management can accept and reject orders. What is the maximal number of orders the restaurant can accept?

No two accepted orders can intersect, i.e. they can't share even a moment of time. If one order ends in the moment other starts, they can't be accepted both.

Input

The first line contains integer number n (1 ≤ n ≤ 5·105) — number of orders. The following n lines contain integer values li and ri each (1 ≤ li ≤ ri ≤ 109).

Output

Print the maximal number of orders that can be accepted.

Examples
input
2
7 11
4 7
output
1
input
5
1 2
2 3
3 4
4 5
5 6
output
3
input
6
4 8
1 5
4 7
2 5
1 3
6 8
output
2
贪心,求最多的不相交线段
#include<bits/stdc++.h>
using namespace std;
struct P
{
int s,e;
}He[5*100000];
bool cmd(P x,P y)
{
return x.e<y.e;
}
int main()
{
int n;
cin>>n;
for(int i=0;i<n;i++)
{
cin>>He[i].s>>He[i].e;
}
sort(He,He+n,cmd);
int sum=He[0].e;
int pos=1;
for(int i=0;i<n;i++)
{
if(He[i].s>sum)
{
sum=He[i].e;
pos++;
}
}
cout<<pos<<endl;
return 0;
}

  

Testing Round #12 B的更多相关文章

  1. Codeforces Testing Round #12 C. Subsequences 树状数组

    C. Subsequences     For the given sequence with n different elements find the number of increasing s ...

  2. Testing Round #12 A

    A. Divisibility time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  3. Codeforces Testing Round #12 C. Subsequences 树状数组维护DP

    C. Subsequences Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/probl ...

  4. Codeforces Testing Round #12 B. Restaurant 贪心

    B. Restaurant Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/problem ...

  5. Codeforces Testing Round #12 A. Divisibility 水题

    A. Divisibility Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/probl ...

  6. Testing Round #12 A,B,C 讨论,贪心,树状数组优化dp

    题目链接:http://codeforces.com/contest/597 A. Divisibility time limit per test 1 second memory limit per ...

  7. Testing Round #12 C

    Description For the given sequence with n different elements find the number of increasing subsequen ...

  8. “玲珑杯”ACM比赛 Round #12题解&源码

    我能说我比较傻么!就只能做一道签到题,没办法,我就先写下A题的题解&源码吧,日后补上剩余题的题解&源码吧!                                     A ...

  9. Codeforces Beta Round #12 (Div 2 Only)

    Codeforces Beta Round #12 (Div 2 Only) http://codeforces.com/contest/12 A 水题 #include<bits/stdc++ ...

随机推荐

  1. C#中如何获取一个二维数组的两维长度,即行数和列数?以及多维数组各个维度的长度?

    如何获取二维数组中的元素个数呢? int[,] array = new int[,] {{1,2,3},{4,5,6},{7,8,9}};//定义一个3行3列的二维数组int row = array. ...

  2. samba server导出/datasmb/目录;samba client挂载/data/至本地的/mydata目录;本地的mysqld或mariadb服务的数据目录设置为/mydata, 要求服务能正常启动,且可正常 存储数据;

    实验环境:CentOS7 主机(mini2) :172.16.250.247  主机名::localhost 客户端(mini3):172.16.253.99  主机名:pxe99 #主机:配置文件的 ...

  3. 奇异值分解(SVD)详解

    2012-04-10 17:38 45524人阅读 评论(18) 收藏 举报  分类: 数学之美 版权声明:本文为博主原创文章,未经博主允许不得转载. SVD分解 SVD分解是LSA的数学基础,本文是 ...

  4. centos6 启动流程

    具体过程:1)加载BIOS的硬件信息,执行BIOS内置程序.2)读取MBR(Master Boot Record)中Boot Loader中的引导信息.3)加载内核Kernel boot到内存中.4) ...

  5. SpringMVC 学习笔记(请求方法的返回值和参数)

    在用注解对配置 处理器时,一般是一个方法处理一个请求,不同方法的返回类型有着不同的意义. 返回值为 ModelAndView 类型 ModelAndView 是Model 和 View 的一个集合类型 ...

  6. C++之string类

    1.String对象的初始化 string s1;               默认构造函数,s1为空串 string s4(n, 'c');     将s4初始化为字符c的n个副本 string s ...

  7. css 雪碧图

    CSS Sprites在国内很多人叫css精灵,是一种网页图片应用处理方式.它允许你将一个页面涉及到的所有零星图片都包含到一张大图中去,这样一来,当访问 该页面时,载入的图片就不会像以前那样一幅一幅地 ...

  8. 关于android中两种service的编写简单总结

    1.startservice (两种方法,继承service类或者继承intentservice 类) 继承service类,在onstartcommend重载方法中实现业务逻辑的处理,如果耗时过长最 ...

  9. 19.Imagetragick 命令执行漏洞(CVE-2016–3714)

    Imagetragick 命令执行漏洞(CVE-2016–3714) 漏洞简介: Imagetragick 命令执行漏洞在16年爆出来以后,wooyun上面也爆出了数个被该漏洞影响的大厂商,像腾讯, ...

  10. 2. DVWA亲测CSRF漏洞

    DVWA登陆      用户名:admin   密码:password Low级: 查看源代码: <?php if (isset($_GET['Change'])) { // Turn requ ...