codeforces-scrape

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

1030B.md (2166B)


      1 Source: https://codeforces.com/problemset/problem/1030/B
      2 
      3 B. Vasya and Cornfield
      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 Vasya owns a cornfield which can be defined with two integers $n$ and $d$. The cornfield can be represented as rectangle with vertices having Cartesian coordinates $(0, d), (d, 0), (n, n - d)$ and $(n - d, n)$.
     22 
     23  ![](https://espresso.codeforces.com/85a2e5c143dc965194b85ea0317c21d39e1c8c99.png) An example of a cornfield with $n = 7$ and $d = 2$. 
     24 
     25 Vasya also knows that there are $m$ grasshoppers near the field (maybe even inside it). The $i$-th grasshopper is at the point $(x_i, y_i)$. Vasya does not like when grasshoppers eat his corn, so for each grasshopper he wants to know whether its position is inside the cornfield (including the border) or outside.
     26 
     27 Help Vasya! For each grasshopper determine if it is inside the field (including the border).
     28 
     29 Input
     30 
     31 The first line contains two integers $n$ and $d$ ($1 \le d \lt n \le 100$).
     32 
     33 The second line contains a single integer $m$ ($1 \le m \le 100$) — the number of grasshoppers.
     34 
     35 The $i$-th of the next $m$ lines contains two integers $x_i$ and $y_i$ ($0 \le x_i, y_i \le n$) — position of the $i$-th grasshopper.
     36 
     37 Output
     38 
     39 Print $m$ lines. The $i$-th line should contain "YES" if the position of the $i$-th grasshopper lies inside or on the border of the cornfield. Otherwise the $i$-th line should contain "NO".
     40 
     41 You can print each letter in any case (upper or lower).
     42 
     43 Examples
     44 
     45 Input
     46 
     47 ```
     48 7 2  
     49 4  
     50 2 4  
     51 4 1  
     52 6 3  
     53 4 5
     54 ```
     55 
     56 Output
     57 
     58 ```
     59 YES  
     60 NO  
     61 NO  
     62 YES
     63 ```
     64 
     65 Input
     66 
     67 ```
     68 8 7  
     69 4  
     70 4 4  
     71 2 8  
     72 8 1  
     73 6 1
     74 ```
     75 
     76 Output
     77 
     78 ```
     79 YES  
     80 NO  
     81 YES  
     82 YES
     83 ```
     84 
     85 Note
     86 
     87 The cornfield from the first example is pictured above. Grasshoppers with indices $1$ (coordinates $(2, 4)$) and $4$ (coordinates $(4, 5)$) are inside the cornfield.
     88 
     89 The cornfield from the second example is pictured below. Grasshoppers with indices $1$ (coordinates $(4, 4)$), $3$ (coordinates $(8, 1)$) and $4$ (coordinates $(6, 1)$) are inside the cornfield.
     90 
     91  ![](https://espresso.codeforces.com/d027bc59468b38c6a2cf18e85b633d1cb2a01910.png)