All submissions for this problem are available.
A sequence of N integers is called K-unique if, when it is split into N/K subsequences of K contiguous elements, each subsequence consists of K distinct integers.
For example, consider this sequence of 6 integers.
(2, 10, 2, 8, 3, 6)
This sequence is 2-unique, because when you split it into 3 subsequences each of 2 contiguous elements as below,
(2, 10), (2, 8), (3, 6),
each subsequence consists of 2 distinct integers.
You are given a sequence of N integers, and a positive integer K. Find a permutation of the sequence that is K-unique.
The first line contains a single integer T, the number of test cases. T test cases follow. The first line of each test case contains two integers N and K. The next line contains a sequence of N integers ai, where ai is the i-th element of the sequence.
For each test case, output a single line containing a permutation of the sequence that is K-unique. The elements of the sequence should be separated by a single space. If there are several solutions, output the lexicographically smallest one. If there is no solution, output -1.
- 1 <= T <= 5
- 1 <= N <= 50000
- 1<= K<= N
- N will be divisible by K
- 0 <= ai <= 1000000000
3 1 1 42 4 2 4 7 7 7 6 2 2 10 2 8 3 6
42 -1 2 3 2 6 8 10
|Tags||fushar, march11, medium|
|Time Limit:||0.695187 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, PERL6, TEXT, PYP3, CLOJ, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.