VEXPROF - The angry professor

The professor was very angry that no students were inside the class when he entered. You are given an array of Time and an integer K. Time[i] is the time student i arrived to the class. As a punishment, the professor allowed the students inside the class only when at least K students waits outside the class. Find the sum of total time wasted for students.

Example Scenario:

Time[] = {1,5,11,12,12}, K=2

At time 1, student0 arrives and waits outside the class.

At time 5, student1 arrives. Student0 and student1 enters inside the class.

At time 11, student2 arrives and waits outside the class.

At time 12, student3 and student4 arrives. Student2,Student3 and Student4 enters inside the class.

Time wasted for student0 = 4

Time wasted for student1 = 0

Time wasted for student2 = 1

Time wasted for student3 = 0

Time wasted for student4 = 0

Total time wasted = 5

Test cases guarantee that all the students entered inside the class.

Input:

The first line consists of an integer t, the number of test cases. For each test case, the first line consists of two integers N(number of students) and K(as defined in the problem statement) followed by N lines each denoting the arrival time of students.

Output:

For each test case, find the total time wasted for the students.

Input Constraints:

1<=t<=100

1<=n<=100000

1<=K<=n

1<=Time[i]<=100

Sample Input:

3

4 4

1

2

2

3

5 4

3

1

2

3

1

4 2

4

3

1

1

Sample Output:

4

5

1


Added by:cegprakash
Date:2014-03-10
Time limit:0.300s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM32-GCC MAWK BC BF C NCSHARP C++ 4.3.2 CPP14 COBOL COFFEE D-CLANG D DART ELIXIR FANTOM FORTH GOSU GRV JULIA KTLN LUA NODEJS OBJC OCAML OCT PIKE PROLOG PYPY3 PYTHON3 R RACKET RUST CHICKEN ST SQLITE SWIFT UNLAMBDA

© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.