Chamber Of Secrets

5

1 votes
Problem

Do you remember Harry, Ron, Hermione and the Chamber Of Secrets.
Evey one has fear of Voldemort, sorry, "You Know who", no one tell his name.
But harry wants to destroy one of the Voldemort's Horcruxes which is Tom Riddle's diary.
So Harry, Ron and Hermione decide that they will go inside the Chamber of Secrets.

 
There are two ways to get inside the Chamber of Secretes.

1. By speaking parseltongue.
2. By makeing any k indexs having same number of bricks.

As Harry knows Parseltongue so he gets inside the Chamber of Secret.
Now, Ron and Hermione want to go inside and the door will open if they make any k index havig same no of bricks. They have an array of N size having some bricks at some index. They are allowed to perform 2 kinds of operations on this array.

1. Type 1: Removing one brick from any index of the array.
2. Type 2: Add one brick to any index of the array.

They can perform these operations as many times as they want on the array.

Each operation of Type 1 reduces their energy by 5 while each operation of Type 2 reduces their energy by 3.

As after getting inside the Chamber of Secret, they have to fight with Voldermot as well, so they want to reduce as much as a minimum amount of their energy.

So tell what is the amount of their energy will be reduced, so they can enter inside the Secret of Chamber.

Input:

The first line contains T indicating test cases. The second line contains 2 integers N indicating the size of the array and K.

The third line contains N space-separated integers denoting the number of bricks at index i of the array.

Note:: Question updated

Output:

The minimum energy will be reduced.

Constraints :

1 ≤ T ≤ 100

1 ≤ K ≤ N ≤100

1 ≤ A[i] ≤100

Time Limit: 0.5
Memory Limit: 64
Source Limit:
Editor Image

?