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:||ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.3.2, CPP 6.3, CPP14, CS2, D, ERL, FORT, FS, GO, HASK, ICK, ICON, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, NODEJS, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH 3.5, RUBY, SCALA, SCM guile, SCM qobi, ST, TEXT, WSPC|
Fetching successful submissions
If you are still having problems, see a sample solution here.