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

题意:

有两台电视,每台可以播放一个时间段的节目,当节目结束的下一个时刻才可以播放其他节目,问是否可以观看全部节目。

对电视设一个判断有无在播放的tag,模拟即可。

AC代码:

 #include<bits/stdc++.h>
using namespace std; struct node{
int s,t;
}a[]; struct tv{
int e;
int tag;
}t[]; int cmp(node x,node y){
if(x.s==y.s)
return x.t<y.t;
else
return x.s<y.s;
} int main(){
ios::sync_with_stdio(false);
int n;
cin>>n;
for(int i=;i<n;i++){
cin>>a[i].s>>a[i].t;
}
sort(a,a+n,cmp);
t[].e=-;
t[].e=-;
t[].tag=;
t[].tag=;
int flag=;
for(int i=;i<n;i++){
if(a[i].s>t[].e){
t[].tag=;
}
else if(a[i].s>t[].e){
t[].tag=;
}
if(!t[].tag){
t[].tag=;
t[].e=a[i].t;
}
else if(!t[].tag){
t[].tag=;
t[].e=a[i].t;
}
else{
flag=;
break;
}
}
if(flag){
cout<<"NO"<<endl;
}
else{
cout<<"YES"<<endl;
}
return ;
}

最新文章

  1. CF724B. Batch Sort[枚举]
  2. JSch - Java实现的SFTP(文件下载详解篇)
  3. Java生成动态GIF图片
  4. Android——例子:简单计算器
  5. long long 读数scanf的转换 #define
  6. LM2596扩流
  7. PHPの页面跳转-常见方法
  8. IEnumerable
  9. (转)C++中返回对象的情形及RVO
  10. Bootstrap入门(五)表单
  11. VMware workstation运维实践系列博客导航
  12. 牛客练习赛7 E 珂朵莉的数列(树状数组+爆long long解决方法)
  13. 分享-结合demo讲解JS引擎工作原理
  14. WEB安全番外第二篇--明日之星介绍HTML5安全问题介绍
  15. nginx学习1
  16. YARN 多租户资源池配置
  17. 手动添加Git Bash到右键菜单
  18. LMAX Disruptor 原理
  19. jxls-2.x导出excel入门——基本操作
  20. 并行程序模拟(Concurrency Simulator, ACM/ICPC World Finals 1991,Uva210)

热门文章

  1. NSSrting的几种经常使用的使用方法
  2. 【BZOJ2510】弱题 期望DP+循环矩阵乘法
  3. Socket的错误码和描述
  4. Java 8 default 函数
  5. php分10个不同等级压缩优化图片(PNG)
  6. 项目log4j日志管理详解
  7. 打造vim成类source insight
  8. Sqooop- 使用Sqoop进行数据的导入导出
  9. 使用 DNSPOD API 实现域名动态解析
  10. JS遍历获取多个控件(使用索引‘i’)