Codeforces Round #638 (Div. 2) B.Phoenix and Beauty

Codeforces Round #638 (Div. 2) B.Phoenix and Beauty

题目链接
Phoenix loves beautiful arrays. An array is beautiful if all its subarrays of length k have the same sum. A subarray of an array is any sequence of consecutive elements.

Phoenix currently has an array a of length n. He wants to insert some number of integers, possibly zero, into his array such that it becomes beautiful. The inserted integers must be between 1 and n inclusive. Integers may be inserted anywhere (even before the first or after the last element), and he is not trying to minimize the number of inserted integers.

Input

The input consists of multiple test cases. The first line contains an integer t (1≤t≤50) — the number of test cases.

The first line of each test case contains two integers n and k (1≤k≤n≤100).

The second line of each test case contains n space-separated integers (1≤ai≤n) — the array that Phoenix currently has. This array may or may not be already beautiful.

Output

For each test case, if it is impossible to create a beautiful array, print -1. Otherwise, print two lines.

The first line should contain the length of the beautiful array m (n≤m≤104). You don’t need to minimize m.

The second line should contain m space-separated integers (1≤bi≤n) — a beautiful array that Phoenix can obtain after inserting some, possibly zero, integers into his array a. You may print integers that weren’t originally in array a.

If there are multiple solutions, print any. It’s guaranteed that if we can make array a beautiful, we can always make it with resulting length no more than 104.

Example

input

4
4 2
1 2 2 1
4 3
1 2 2 1
3 2
1 2 3
4 4
4 3 4 2

output

5
1 2 1 2 1
4
1 2 2 1
-1
7
4 3 2 1 4 3 2

典型的循环节思维题~
首先题目对长度不作要求,那么如果满足条件我们肯定输出 n n n 个长度为 k k k 循环节,这样最方便~
考虑输出 -1 的情况,对长度为 k k k 的循环节,如果数的种类数超过 k k k,一定是不满足的,所以可以用 m a p map map s e t set set 记录种类数判断即可~
下面考虑种类数小于 k k k 的情况数,那么我们可以通过补 1 来增加循环节的长度,AC代码如下:

#include
using namespace std;
typedef long long ll;

int main()
{
    int t,n,k,x;
    cin>>t;
    while(t--){
       cin>>n>>k;
       set<int>s;
       for(int i=0;i<n;i++) cin>>x,s.insert(x);
       if(s.size()>k) puts("-1");
       else{
            cout<<n*k<<endl;
            for(int i=0;i<n;i++){
                for(auto j:s) cout<<j<<" ";
                for(int j=0;j<k-s.size();j++) cout<<1<<" ";
            }
            puts("");
       }
    }
    return 0;
}

你可能感兴趣的:(思维,Codeforces)