codeforces 845C Two TVs

来源:互联网 发布:9008端口刷机工具 编辑:程序博客网 时间:2024/05/12 01:00

C. Two TVs
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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·105) — the number of shows.

Each of the next n lines contains two integers li and ri (0 ≤ li < ri ≤ 109) — 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
31 22 34 5
output
YES
input
41 22 32 31 2
output
NO

题意:给两个电视机,一个节目的开始时间和一个节目的结束时间相同,则这两个节目只能在不同电视机上,问给定节目能否看完

对开始时间进行排序,再模拟一下就好


#pragma comment(linker,"/STACK:1024000000,1024000000")#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<string>#include<stack>#include<queue>#include<deque>#include<set>#include<map>#include<cmath>#include<vector>using namespace std;typedef long long ll;typedef unsigned long long ull;typedef pair<int, int> PII;#define pi acos(-1.0)#define eps 1e-10#define pf printf#define sf scanf#define lson rt<<1,l,m#define rson rt<<1|1,m+1,r#define e tree[rt]#define _s second#define _f first#define all(x) (x).begin,(x).end#define mem(i,a) memset(i,a,sizeof i)#define for0(i,a) for(int (i)=0;(i)<(a);(i)++)#define for1(i,a) for(int (i)=1;(i)<=(a);(i)++)#define mi ((l+r)>>1)#define sqr(x) ((x)*(x))const int inf=0x3f3f3f3f;const int Max=2e5+1;int L,l,R,r,n;struct node{    int x,y;}t[Max];bool cmp(const node& a,const node& b){    return a.x<b.x;}int main(){    while(~sf("%d",&n))    {        L=R=l=r=-1;//初始化,两个电视均无播出节目        int tag=1;        for1(i,n)            sf("%d%d",&t[i].x,&t[i].y);        sort(t+1,t+n+1,cmp);        for1(i,n)        {            if(L==-1||t[i].x>R)//第一个电视无节目或播出时间在结束之后(不能相等)                L=t[i].x,R=t[i].y;            else            {                if(l==-1||t[i].x>r)                    l=t[i].x,r=t[i].y;                else                    tag=0;            }        }        puts(tag?"YES":"NO");    }    return 0;}






原创粉丝点击