codeforces 845C Two TVs

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
3
1 2
2 3
4 5
output
YES
input
4
1 2
2 3
2 3
1 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;
}






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值