BETA

Difficulty Level:

Easy

Total Submissions: 987 Accuracy:

17.93%

Maximum weight difference
     

Given an array. The task is to choose K numbers from the array such that the absolute difference between the sum of chosen numbers and the sum of remaining numbers is maximum.

Input:
The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case consists of two lines. First line of each test case contains two integers N and K and the second line contains N space separated array elements.

Output:
For each test case, print the maximum absolute difference in new line.

Constraints:
1<=T<=200
1<=K<=N<=105
1<=A[i]<=106

Example:
Input:

2
5 2
8 4 5  2 10
8 3
1 1 1 1 1 1 1 1

Output:
17
2

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Arun Tyagi

Set Default Code

					   
It is recommended to 'Compile & Test' your code before clicking 'Submit'!

Compilation/Execution Result:

Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.