codeforces-scrape

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

884B.md (1754B)


      1 Source: https://codeforces.com/problemset/problem/884/B
      2 
      3 B. Japanese Crosswords Strike Back
      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 A one-dimensional Japanese crossword can be represented as a binary string of length *x*. An encoding of this crossword is an array *a* of size *n*, where *n* is the number of segments formed completely of 1's, and *a**i* is the length of *i*-th segment. No two segments touch or intersect.
     22 
     23 For example:
     24 
     25 * If *x* = 6 and the crossword is 111011, then its encoding is an array {3, 2};
     26 * If *x* = 8 and the crossword is 01101010, then its encoding is an array {2, 1, 1};
     27 * If *x* = 5 and the crossword is 11111, then its encoding is an array {5};
     28 * If *x* = 5 and the crossword is 00000, then its encoding is an empty array.
     29 
     30 Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it!
     31 
     32 Input
     33 
     34 The first line contains two integer numbers *n* and *x* (1 ≤ *n* ≤ 100000, 1 ≤ *x* ≤ 109) — the number of elements in the encoding and the length of the crossword Mishka picked.
     35 
     36 The second line contains *n* integer numbers *a*1, *a*2, ..., *a**n* (1 ≤ *a**i* ≤ 10000) — the encoding.
     37 
     38 Output
     39 
     40 Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO.
     41 
     42 Examples
     43 
     44 Input
     45 
     46 ```
     47 2 4  
     48 1 3
     49 ```
     50 
     51 Output
     52 
     53 ```
     54 NO
     55 ```
     56 
     57 Input
     58 
     59 ```
     60 3 10  
     61 3 3 2
     62 ```
     63 
     64 Output
     65 
     66 ```
     67 YES
     68 ```
     69 
     70 Input
     71 
     72 ```
     73 2 10  
     74 1 3
     75 ```
     76 
     77 Output
     78 
     79 ```
     80 NO
     81 ```