codeforces-scrape

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

1494B.md (1514B)


      1 Source: https://codeforces.com/problemset/problem/1494/B
      2 
      3 B. Berland Crossword
      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 Berland crossword is a puzzle that is solved on a square grid with $n$ rows and $n$ columns. Initially all the cells are white.
     22 
     23 To solve the puzzle one has to color some cells on the border of the grid black in such a way that:
     24 
     25 * exactly $U$ cells in the top row are black;
     26 * exactly $R$ cells in the rightmost column are black;
     27 * exactly $D$ cells in the bottom row are black;
     28 * exactly $L$ cells in the leftmost column are black.
     29 
     30 Note that you can color zero cells black and leave every cell white.
     31 
     32 Your task is to check if there exists a solution to the given puzzle.
     33 
     34 Input
     35 
     36 The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of testcases.
     37 
     38 Then the descriptions of $t$ testcases follow.
     39 
     40 The only line of each testcase contains $5$ integers $n, U, R, D, L$ ($2 \le n \le 100$; $0 \le U, R, D, L \le n$).
     41 
     42 Output
     43 
     44 For each testcase print "YES" if the solution exists and "NO" otherwise.
     45 
     46 You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES are all recognized as positive answer).
     47 
     48 Example
     49 
     50 Input
     51 
     52 ```
     53 4
     54 5 2 5 3 1
     55 3 0 0 0 0
     56 4 4 1 4 0
     57 2 1 1 1 1
     58 ```
     59 
     60 Output
     61 
     62 ```
     63 YES
     64 YES
     65 NO
     66 YES
     67 ```
     68 
     69 Note
     70 
     71 Here are possible solutions to testcases $1$, $2$ and $4$:
     72 
     73  ![](https://espresso.codeforces.com/843e1546913a7aed3f0e8cfba6c2e583c2e3c443.png)