## 小坏蛋_千千

I was caught in a heavy rain!

# Codeforces 845 C. Two TVs （模拟）

## Description

Polycarp is a great fan of television.

He wrote down all the TV programs he is interested in for today. His list contains n shows, i-th of them starts at moment li and ends at moment ri.

Polycarp owns two TVs. He can watch two different shows simultaneously with two TVs but he can only watch one show at any given moment on a single TV. If one show ends at the same moment some other show starts then you can’t watch them on a single TV.

Polycarp wants to check out all n shows. Are two TVs enough to do so?

## Input

The first line contains one integer n (1 ≤ n ≤ 2·10^5) — the number of shows.

Each of the next n lines contains two integers li and ri (0 ≤ li < ri ≤ 10^9) — starting and ending time of i-th show.

## Output

If Polycarp is able to check out all the shows using only two TVs then print “YES” (without quotes). Otherwise, print “NO” (without quotes).

## Examples input

3
1 2
2 3
4 5


## Examples output

YES


## AC 代码

#include<bits/stdc++.h>
#define IO ios::sync_with_stdio(false);\
cin.tie(0);\
cout.tie(0);
using namespace std;
typedef long long LL;
const int maxn = 2e5+10;

struct node
{
int l,r;
} a[maxn];
int n;

bool judge()
{
int tv1 = INT_MIN;
int tv2 = INT_MIN;
for(int i=0; i<n; i++)
{
if(a[i].l>tv1)
tv1 = a[i].r;
else if(a[i].l>tv2)
tv2 = a[i].r;
else
return false;
}
return true;
}

int main()
{
IO;
cin>>n;
for(int i=0; i<n; i++)
{
cin>>a[i].l>>a[i].r;
}
sort(a,a+n,[](const node &x,const node &y)
{
if(x.l==y.l)
return x.r<y.r;
return x.l<y.l;
});
cout<<(judge()?"YES":"NO")<<endl;
return 0;
}

#### Codeforces-845C：Two TVs(思维)

2017-09-08 15:40:45

#### codeforce_845c_Two TVs

2018-04-03 01:58:13

#### CodeForces 845C Two TVs (模拟)

2017-09-06 18:17:34

#### Codeforces 845 C Two TVs

2017-08-23 01:11:18

#### codeforces 526 E(神题)

2015-04-13 22:07:06

#### Codeforces #488div.2 - 994C - Two Squares(计算几何入门)

2018-06-17 03:13:30

#### Codeforces 964C Alternating Sum

2018-04-18 16:23:24

#### Two Squares CodeForces - 994C（思维）

2018-06-17 18:57:33

#### Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) C. Fountains（树状数组）

2017-05-12 07:53:50