Chef and Replication
All submissions for this problem are available.Chef Avi likes the number $K$. Given a list of $N$ integers, help him find the sum of all distinct numbers repeating exactly $K$ times. Each of those numbers should be considered only once in the sum, not $K$ times. ###Input: - First line will contain $T$, number of testcases. Then the testcases follow. - Each testcase contains two lines: - The first line contains two space-separated integers $N, K$. - The second line contains $N$ space-separated integers. ###Output: For each testcase, print the sum of all numbers occurring exactly $K$ times. If there is no such number, print -1 instead. ###Constraints - $1\leq T\leq 10$ - $1\leq N\leq10,000$ - $1 \leq K \leq N$ - $0 \leq A_i \leq 10^9$ ###Sample Input: 3 4 1 2 3 4 4 5 3 9 9 1 1 9 2 1 2 2 ###Sample Output: 5 9 -1 ###Explanation: Test Case 1: The numbers 2 and 3 occur exactly once. So the answer is 2 + 3 = 5. Test Case 2: The number 9 occurs exactly three times. So the answer is 9. Test Case 3: There is no number which occurs exactly once. Hence the answer is -1.
|Time Limit:||0.5 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, 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, TCL, kotlin, PERL6, TEXT, SCM chicken, PYP3, CLOJ, COB, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.