CF1408B.Arrays Sum

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a non-decreasing array of non-negative integers a1,a2,…,ana_1, a_2, \ldots, a_n. Also you are given a positive integer kk.

You want to find mm non-decreasing arrays of non-negative integers b1,b2,…,bmb_1, b_2, \ldots, b_m, such that:

  • The size of bib_i is equal to nn for all 1≤i≤m1 \leq i \leq m.
  • For all 1≤j≤n1 \leq j \leq n, aj=b1,j+b2,j+…+bm,ja_j = b_{1, j} + b_{2, j} + \ldots + b_{m, j}. In the other word, array aa is the sum of arrays bib_i.
  • The number of different elements in the array bib_i is at most kk for all 1≤i≤m1 \leq i \leq m.

Find the minimum possible value of mm, or report that there is no possible mm.

给你一个非递减的非负整数数组 a1,a2,…,ana_1, a_2, \ldots, a_n,以及一个正整数 kk。

你需要找出 mm 个非递减的非负整数数组 b1,b2,…,bmb_1, b_2, \ldots, b_m,满足以下条件:

  • 对所有 1≤i≤m1 \leq i \leq m,数组 bib_i 的长度等于 nn;
  • 对所有 1≤j≤n1 \leq j \leq n,有 aj=b1,j+b2,j+…+bm,ja_j = b_{1, j} + b_{2, j} + \ldots + b_{m, j}。换言之,数组 aa 是各数组 bib_i 的逐元素和;
  • 对所有 1≤i≤m1 \leq i \leq m,数组 bib_i 中不同元素的个数至多为 kk。

求满足条件的最小可能的 mm 值;若不存在这样的 mm,则报告无解。

输入格式

The first line contains one integer tt (1≤t≤1001 \leq t \leq 100): the number of test cases.

The first line of each test case contains two integers nn, kk (1≤n≤1001 \leq n \leq 100, 1≤k≤n1 \leq k \leq n).

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (0≤a1≤a2≤…≤an≤1000 \leq a_1 \leq a_2 \leq \ldots \leq a_n \leq 100, an>0a_n \gt 0).

第一行包含一个整数 tt(1≤t≤1001 \leq t \leq 100):测试用例的数量。

每个测试用例的第一行包含两个整数 nn、kk(1≤n≤1001 \leq n \leq 100,1≤k≤n1 \leq k \leq n)。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(0≤a1≤a2≤…≤an≤1000 \leq a_1 \leq a_2 \leq \ldots \leq a_n \leq 100,且 an>0a_n \gt 0)。

输出格式

For each test case print a single integer: the minimum possible value of mm. If there is no such mm, print −1-1.

对于每个测试用例,输出一个整数:满足条件的最小 mm 值。若不存在这样的 mm,则输出 −1-1。

输入输出样例

  • 输入#1

    6
    4 1
    0 0 0 1
    3 1
    3 3 3
    11 3
    0 1 2 2 3 3 3 4 4 4 4
    5 3
    1 2 3 4 5
    9 4
    2 2 3 5 7 11 13 13 17
    10 7
    0 1 1 2 3 3 4 5 5 6

    输出#1

    -1
    1
    2
    2
    2
    1

说明/提示

In the first test case, there is no possible mm, because all elements of all arrays should be equal to 00. But in this case, it is impossible to get a4=1a_4 = 1 as the sum of zeros.

In the second test case, we can take b1=[3,3,3]b_1 = [3, 3, 3]. 11 is the smallest possible value of mm.

In the third test case, we can take b1=[0,1,1,1,2,2,2,2,2,2,2]b_1 = [0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2] and b2=[0,0,1,1,1,1,1,2,2,2,2]b_2 = [0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2]. It's easy to see, that ai=b1,i+b2,ia_i = b_{1, i} + b_{2, i} for all ii and the number of different elements in b1b_1 and in b2b_2 is equal to 33 (so it is at most 33). It can be proven that 22 is the smallest possible value of mm.

在第一个测试用例中,不存在满足条件的 mm,因为所有数组中的所有元素都必须等于 00。但在这种情况下,不可能通过若干个 00 的和得到 a4=1a_4 = 1。

在第二个测试用例中,我们可以取 b1=[3,3,3]b_1 = [3, 3, 3]。此时 mm 的最小可能值为 11。

在第三个测试用例中,我们可以取 b1=[0,1,1,1,2,2,2,2,2,2,2]b_1 = [0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2] 和 b2=[0,0,1,1,1,1,1,2,2,2,2]b_2 = [0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2]。容易验证,对所有 ii 均有 ai=b1,i+b2,ia_i = b_{1, i} + b_{2, i},且 b1b_1 与 b2b_2 中不同元素的个数均为 33(即均不超过 33)。可以证明,mm 的最小可能值为 22。

输入解题思路,AI测评打分。不知道怎么写?

首页