codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

845C.md (1253B)


      1 Source: https://codeforces.com/problemset/problem/845/C
      2 
      3 C. Two TVs
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 Polycarp is a great fan of television.
     22 
     23 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 *l**i* and ends at moment *r**i*.
     24 
     25 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.
     26 
     27 Polycarp wants to check out all *n* shows. Are two TVs enough to do so?
     28 
     29 Input
     30 
     31 The first line contains one integer *n* (1 ≤ *n* ≤ 2·105) — the number of shows.
     32 
     33 Each of the next *n* lines contains two integers *l**i* and *r**i* (0 ≤ *l**i* < *r**i* ≤ 109) — starting and ending time of *i*-th show.
     34 
     35 Output
     36 
     37 If Polycarp is able to check out all the shows using only two TVs then print "YES" (without quotes). Otherwise, print "NO" (without quotes).
     38 
     39 Examples
     40 
     41 Input
     42 
     43 ```
     44 3  
     45 1 2  
     46 2 3  
     47 4 5
     48 ```
     49 
     50 Output
     51 
     52 ```
     53 YES
     54 ```
     55 
     56 Input
     57 
     58 ```
     59 4  
     60 1 2  
     61 2 3  
     62 2 3  
     63 1 2
     64 ```
     65 
     66 Output
     67 
     68 ```
     69 NO
     70 ```