B. Arrays Sum

B. Arrays Sum

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given a non-decreasing array of non-negative integers a1,a2,…,ana1,a2,…,an. Also you are given a positive integer kk.

You want to find mm non-decreasing arrays of non-negative integers b1,b2,…,bmb1,b2,…,bm, such that:

  • The size of bibi is equal to nn for all 1≤i≤m1≤i≤m.
  • For all 1≤j≤n1≤j≤n, aj=b1,j+b2,j+…+bm,jaj=b1,j+b2,j+…+bm,j. In the other word, array aa is the sum of arrays bibi.
  • The number of different elements in the array bibi is at most kk for all 1≤i≤m1≤i≤m.

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

Input

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

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

The second line contains nn integers a1,a2,…,ana1,a2,…,an (0≤a1≤a2≤…≤an≤1000≤a1≤a2≤…≤an≤100, an>0an>0).

Output

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

Example

input

Copy

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

output

Copy

-1
1
2
2
2
1

Note

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=1a4=1 as the sum of zeros.

In the second test case, we can take b1=[3,3,3]b1=[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]b1=[0,1,1,1,2,2,2,2,2,2,2] and b2=[0,0,1,1,1,1,1,2,2,2,2]b2=[0,0,1,1,1,1,1,2,2,2,2]. It's easy to see, that ai=b1,i+b2,iai=b1,i+b2,i for all ii and the number of different elements in b1b1 and in b2b2 is equal to 33 (so it is at most 33). It can be proven that 22 is the smallest possible value of mm.

本题并不是多难构造,难在本题题意不易理解

突破点在于a数组是不减的,意味着相同的数字是堆积在一起的,另一个突破点是b数组的长度也要为n,每次我们最多用k种,那么第一次可以用k种,第二次我们在原来k种的位置上全部填上0,在扩展k-1种即可,第三次也是k-1种,这样就能最少的次数了,进行一次特判无解,种类数不是1,但是每次只能用1种的时候,剩下的我们都能构造出来用解的情况,因为每次至少是可以扩展新的一种的

#include<iostream>
# include<algorithm>
# include<unordered_map>
# include<cstring>

using namespace std;
typedef long long int  ll;

bool mp[110];
int a[110];
int main ()
{

    int t;
    cin>>t;
    while(t--)
    {
        int n,k;
        cin>>n>>k;
        int cnt=0;
        memset(mp,0,sizeof(mp));
        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
            if(mp[a[i]]==0)
            {
                mp[a[i]]=1;
                cnt++;
            }

        }
        if(k==1&&cnt!=1)
        {
           cout<<"-1"<<endl;
        }
        else
        {
            if(cnt==1)
            {
                cout<<1<<endl;
                continue;

            }
            cnt--;
            int ans=cnt/(k-1);
            if(cnt%(k-1))
                ans++;
            cout<<ans<<endl;
        }
    }
    return 0;

}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

qinsanma and Code

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值