c语言一维数组怎么快速排列
258
2022-09-06
cfC. Two TVs
C. Two TVs time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard 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减1操作判断是否该电视机在占用, 要注意同一时刻电视机结束放映并开始放映是不行的,也就是结束必须在等1个时间之后才能放。 涉及到离散化最后一个端点,最后一个端点必须+1.
#include
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~