codeforces-scrape

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

1408B.md (2074B)


      1 Source: https://codeforces.com/problemset/problem/1408/B
      2 
      3 B. Arrays Sum
      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 You are given a non-decreasing array of non-negative integers $a_1, a_2, \ldots, a_n$. Also you are given a positive integer $k$.
     22 
     23 You want to find $m$ non-decreasing arrays of non-negative integers $b_1, b_2, \ldots, b_m$, such that:
     24 
     25 * The size of $b_i$ is equal to $n$ for all $1 \leq i \leq m$.
     26 * For all $1 \leq j \leq n$, $a_j = b_{1, j} + b_{2, j} + \ldots + b_{m, j}$. In the other word, array $a$ is the sum of arrays $b_i$.
     27 * The number of different elements in the array $b_i$ is at most $k$ for all $1 \leq i \leq m$.
     28 
     29 Find the minimum possible value of $m$, or report that there is no possible $m$.
     30 
     31 Input
     32 
     33 The first line contains one integer $t$ ($1 \leq t \leq 100$): the number of test cases.
     34 
     35 The first line of each test case contains two integers $n$, $k$ ($1 \leq n \leq 100$, $1 \leq k \leq n$).
     36 
     37 The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \leq a_1 \leq a_2 \leq \ldots \leq a_n \leq 100$, $a_n \gt 0$).
     38 
     39 Output
     40 
     41 For each test case print a single integer: the minimum possible value of $m$. If there is no such $m$, print $-1$.
     42 
     43 Example
     44 
     45 Input
     46 
     47 ```
     48 6
     49 4 1
     50 0 0 0 1
     51 3 1
     52 3 3 3
     53 11 3
     54 0 1 2 2 3 3 3 4 4 4 4
     55 5 3
     56 1 2 3 4 5
     57 9 4
     58 2 2 3 5 7 11 13 13 17
     59 10 7
     60 0 1 1 2 3 3 4 5 5 6
     61 ```
     62 
     63 Output
     64 
     65 ```
     66 -1
     67 1
     68 2
     69 2
     70 2
     71 1
     72 ```
     73 
     74 Note
     75 
     76 In the first test case, there is no possible $m$, because all elements of all arrays should be equal to $0$. But in this case, it is impossible to get $a_4 = 1$ as the sum of zeros.
     77 
     78 In the second test case, we can take $b_1 = [3, 3, 3]$. $1$ is the smallest possible value of $m$.
     79 
     80 In the third test case, we can take $b_1 = [0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2]$ and $b_2 = [0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2]$. It's easy to see, that $a_i = b_{1, i} + b_{2, i}$ for all $i$ and the number of different elements in $b_1$ and in $b_2$ is equal to $3$ (so it is at most $3$). It can be proven that $2$ is the smallest possible value of $m$.