Roses for Alexey
All submissions for this problem are available.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
It's Valentine's day today. Alexey's flower shop has received lots of orders of bouquets of roses. The shop provides bouquets that contain exactly K roses, all of equal length.
Alexey daily asks his delivery persons to obtain N newly-plucked fresh roses from the nearby garden. The lengths of these roses are given to you by an array A of size N. Now, he wants to make maximum number of bouquets from these roses. He can pick a rose and cut it to any length he wants. Note that the leftover part of a rose after cutting cannot be reused and will have to be thrown.
One can easily see that Alexey can create a maximum of N / K bouquets. It is guaranteed in the problem that N is divisible by K. For obtaining these many requests, he wants to cut as few roses as possible. Can you please tell what is the minimum number of roses that will need to be cut in order to get N / K bouquets?
The first line of input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains two space-separated integers N and K, denoting the number of roses and the number of roses in one bouquet.
The second line contains N space-separated integers A1, A2, ..., AN denoting the lengths of roses.
For each test case, output a single line containing the minimum number of roses that need to be cut.
- 1 ≤ T ≤ 10
- 2 ≤ N ≤ 100 000
- 1 ≤ Ai ≤ 1018
- 1 ≤ K ≤ N
- N % K = 0 for each test case
Input: 2 8 4 1 2 2 3 4 5 5 6 4 4 1 1 1 3 Output: 5 1
Case 1: Alexey cut two roses of length 5 to length 2 and get the first bouquet with each rose length being 2. The other roses with length 3,4,6 can be cut to length 1 and he gets the second bouquet in which each rose will be of length 1.
Case 2: The last rose can be cut to length 1. There will be a bouquet with each rose of length 1.
|Time Limit:||2 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, 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, TCL, PERL6, TEXT, SCM chicken, PYP3, CLOJ, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.