codeforces-scrape

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

1774B.md (1931B)


      1 Source: https://codeforces.com/problemset/problem/1774/B
      2 
      3 B. Coloring
      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 Cirno_9baka has a paper tape with $n$ cells in a row on it. As he thinks that the blank paper tape is too dull, he wants to paint these cells with $m$ kinds of colors. For some aesthetic reasons, he thinks that the $i$-th color must be used exactly $a_i$ times, and for every $k$ consecutive cells, their colors have to be distinct.
     22 
     23 Help Cirno_9baka to figure out if there is such a way to paint the cells.
     24 
     25 Input
     26 
     27 The first line contains a single integer $t$ ($1 \leq t \leq 10\,000$)  — the number of test cases. The description of test cases follows.
     28 
     29 The first line of each test case contains three integers $n$, $m$, $k$ ($1 \leq k \leq n \leq 10^9$, $1 \leq m \leq 10^5$, $m \leq n$). Here $n$ denotes the number of cells, $m$ denotes the number of colors, and $k$ means that for every $k$ consecutive cells, their colors have to be distinct.
     30 
     31 The second line of each test case contains $m$ integers $a_1, a_2, \cdots , a_m$ ($1 \leq a_i \leq n$)  — the numbers of times that colors have to be used. It's guaranteed that $a_1 + a_2 + \ldots + a_m = n$.
     32 
     33 It is guaranteed that the sum of $m$ over all test cases does not exceed $10^5$.
     34 
     35 Output
     36 
     37 For each test case, output "YES" if there is at least one possible coloring scheme; otherwise, output "NO".
     38 
     39 You may print each letter in any case (for example, "YES", "Yes", "yes", and "yEs" will all be recognized as positive answers).
     40 
     41 Example
     42 
     43 Input
     44 
     45 ```
     46 2
     47 
     48 12 6 2
     49 
     50 1 1 1 1 1 7
     51 
     52 12 6 2
     53 
     54 2 2 2 2 2 2
     55 ```
     56 
     57 Output
     58 
     59 ```
     60 NO
     61 YES
     62 ```
     63 
     64 Note
     65 
     66 In the first test case, there is no way to color the cells satisfying all the conditions.
     67 
     68 In the second test case, we can color the cells as follows: $(1, 2, 1, 2, 3, 4, 3, 4, 5, 6, 5, 6)$. For any $2$ consecutive cells, their colors are distinct.