codeforces-scrape

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

902A.md (2356B)


      1 Source: https://codeforces.com/problemset/problem/902/A
      2 
      3 A. Visiting a Friend
      4 
      5 time limit per test
      6 
      7 1 second
      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 Pig is visiting a friend.
     22 
     23 Pig's house is located at point 0, and his friend's house is located at point *m* on an axis.
     24 
     25 Pig can use teleports to move along the axis.
     26 
     27 To use a teleport, Pig should come to a certain point (where the teleport is located) and choose where to move: for each teleport there is the rightmost point it can move Pig to, this point is known as the limit of the teleport.
     28 
     29 Formally, a teleport located at point *x* with limit *y* can move Pig from point *x* to any point within the segment [*x*; *y*], including the bounds.
     30 
     31  ![](https://espresso.codeforces.com/ac5b7c8a91aa8756da17036e40160876c65231c3.png) 
     32 
     33 Determine if Pig can visit the friend using teleports only, or he should use his car.
     34 
     35 Input
     36 
     37 The first line contains two integers *n* and *m* (1 ≤ *n* ≤ 100, 1 ≤ *m* ≤ 100) — the number of teleports and the location of the friend's house.
     38 
     39 The next *n* lines contain information about teleports.
     40 
     41 The *i*-th of these lines contains two integers *a**i* and *b**i* (0 ≤ *a**i* ≤ *b**i* ≤ *m*), where *a**i* is the location of the *i*-th teleport, and *b**i* is its limit.
     42 
     43 It is guaranteed that *a**i* ≥ *a**i* - 1 for every *i* (2 ≤ *i* ≤ *n*).
     44 
     45 Output
     46 
     47 Print "YES" if there is a path from Pig's house to his friend's house that uses only teleports, and "NO" otherwise.
     48 
     49 You can print each letter in arbitrary case (upper or lower).
     50 
     51 Examples
     52 
     53 Input
     54 
     55 ```
     56 3 5  
     57 0 2  
     58 2 4  
     59 3 5
     60 ```
     61 
     62 Output
     63 
     64 ```
     65 YES
     66 ```
     67 
     68 Input
     69 
     70 ```
     71 3 7  
     72 0 4  
     73 2 5  
     74 6 7
     75 ```
     76 
     77 Output
     78 
     79 ```
     80 NO
     81 ```
     82 
     83 Note
     84 
     85 The first example is shown on the picture below:
     86 
     87  ![](https://espresso.codeforces.com/97af9c02f6fbd10e07baa36e74770261d93d5c70.png) 
     88 
     89 Pig can use the first teleport from his house (point 0) to reach point 2, then using the second teleport go from point 2 to point 3, then using the third teleport go from point 3 to point 5, where his friend lives.
     90 
     91 The second example is shown on the picture below:
     92 
     93  ![](https://espresso.codeforces.com/122f57806a14b001c70f0ae56f5369c9a3867820.png) 
     94 
     95 You can see that there is no path from Pig's house to his friend's house that uses only teleports.