当前位置:   article > 正文

codeforces 845C Two TVs

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

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

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


  1. #pragma comment(linker,"/STACK:1024000000,1024000000")
  2. #include<iostream>
  3. #include<cstdio>
  4. #include<algorithm>
  5. #include<cstring>
  6. #include<string>
  7. #include<stack>
  8. #include<queue>
  9. #include<deque>
  10. #include<set>
  11. #include<map>
  12. #include<cmath>
  13. #include<vector>
  14. using namespace std;
  15. typedef long long ll;
  16. typedef unsigned long long ull;
  17. typedef pair<int, int> PII;
  18. #define pi acos(-1.0)
  19. #define eps 1e-10
  20. #define pf printf
  21. #define sf scanf
  22. #define lson rt<<1,l,m
  23. #define rson rt<<1|1,m+1,r
  24. #define e tree[rt]
  25. #define _s second
  26. #define _f first
  27. #define all(x) (x).begin,(x).end
  28. #define mem(i,a) memset(i,a,sizeof i)
  29. #define for0(i,a) for(int (i)=0;(i)<(a);(i)++)
  30. #define for1(i,a) for(int (i)=1;(i)<=(a);(i)++)
  31. #define mi ((l+r)>>1)
  32. #define sqr(x) ((x)*(x))
  33. const int inf=0x3f3f3f3f;
  34. const int Max=2e5+1;
  35. int L,l,R,r,n;
  36. struct node
  37. {
  38. int x,y;
  39. }t[Max];
  40. bool cmp(const node& a,const node& b)
  41. {
  42. return a.x<b.x;
  43. }
  44. int main()
  45. {
  46. while(~sf("%d",&n))
  47. {
  48. L=R=l=r=-1;//初始化,两个电视均无播出节目
  49. int tag=1;
  50. for1(i,n)
  51. sf("%d%d",&t[i].x,&t[i].y);
  52. sort(t+1,t+n+1,cmp);
  53. for1(i,n)
  54. {
  55. if(L==-1||t[i].x>R)//第一个电视无节目或播出时间在结束之后(不能相等)
  56. L=t[i].x,R=t[i].y;
  57. else
  58. {
  59. if(l==-1||t[i].x>r)
  60. l=t[i].x,r=t[i].y;
  61. else
  62. tag=0;
  63. }
  64. }
  65. puts(tag?"YES":"NO");
  66. }
  67. return 0;
  68. }






声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/71553
推荐阅读
相关标签
  

闽ICP备14008679号