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. px-rem自适应转换(进阶@rem:40rem; )

    接力之前的文章 https://www.cnblogs.com/leshao/p/5674710.html 这篇文章讲解的是px -rem 单位换算 除100的  写法 比如实际测量PSD宽度是500 ...

  2. Muduo 多线程模型:一个 Sudoku 服务器演变

    陈硕 (giantchen AT gmail) blog.csdn.net/Solstice Muduo 全系列文章列表: http://blog.csdn.net/Solstice/category ...

  3. [转]jQuery.extend 函数详解

    JQuery的extend扩展方法:      Jquery的扩展方法extend是我们在写插件的过程中常用的方法,该方法有一些重载原型,在此,我们一起去了解了解.      一.Jquery的扩展方 ...

  4. 十二:JAVA I/O

     输入模式                                                          输出模式 ⑴字节输入流:InputStream ⑵字节输出流:Output ...

  5. C笔试题(一)

    a和b两个整数,不用if, while, switch, for,>, <, >=, <=, ?:,求出两者的较大值. 答案: int func(int a, int b) { ...

  6. shutdown-用于关闭/重启计算机

    Linux系统下的shutdown命令用于安全的关闭/重启计算机,它不仅可以方便的实现定时关机,还可以由用户决定关机时的相关参数.在执行shutdown命令时,系统会给每个终端(用户)发送一条屏显,提 ...

  7. SharePoint 无法“使用资源管理器打开”

    提示错误信息: 在文件资源管理器中打开此位置时遇到问题.将此网站添加到受信任的站点列表,然后重试. 服务器情况: 安装 Internet Explorer 10 后,在 Windows 资源管理器中打 ...

  8. AngularJs(Part 6)

    Overcomming same-origin policy restrictions with JSONP. AJAX has a restriction that it can only retr ...

  9. PCLVisualizer可视化类(3)

    viewer->addLine<pcl::PointXYZRGB> (cloud->points[0], cloud->points[cloud->size() - ...

  10. 26、HDF5 文件格式简介

    转载:庐州月光 http://www.cnblogs.com/xudongliang/p/6907733.html 三代测序下机的原始数据不再是fastq格式了,而是换成了hdf5 格式,在做三代数据 ...