#P1847A. The Man who became a God
The Man who became a God
Description
Kars is tired and resentful of the narrow mindset of his village since they are content with staying where they are and are not trying to become the perfect life form. Being a top-notch inventor, Kars wishes to enhance his body and become the perfect life form. Unfortunately, of the villagers have become suspicious of his ideas. The -th villager has a suspicion of on him. Individually each villager is scared of Kars, so they form into groups to be more powerful.
The power of the group of villagers from to be defined as where
Here is the absolute value of . A group with only one villager has a power of .
Kars wants to break the villagers into exactly contiguous subgroups so that the sum of their power is minimized. Formally, he must find positive integers such that is minimised. Help Kars in finding the minimum value of .
The first line contains a single integer — the number of test cases. The description of test cases follows.
The first line of each test case contains two integers — the number of villagers and the number of groups they must be split into.
The second line of each test case contains integers — the suspicion of each of the villagers.
For each test case, output a single integer — the minimum possible value of sum of power of all the groups i. e. the minimum possible value of .
Input
The first line contains a single integer — the number of test cases. The description of test cases follows.
The first line of each test case contains two integers — the number of villagers and the number of groups they must be split into.
The second line of each test case contains integers — the suspicion of each of the villagers.
Output
For each test case, output a single integer — the minimum possible value of sum of power of all the groups i. e. the minimum possible value of .
Note
In the first test case, we will group the villagers with suspicion into and . So, .
In the second test case, we will group the villagers with suspicion into . So, .