Http://poj.org/problem? Id = 3709
Given a non-strictly monotonically incrementing series A1,..., An. Each operation can reduce the value of any item in the series by 1. Now we need to make each item in the series meet at least one of the other items that is equal to its K-1. Calculate the minimum number of operations on this sequence.
Input: number of groups of the first behavior test data t (1 ≤T≤ 20)
Each group of test data contains two rows:
The first behavior is two positive integers n, k. N is the number of elements in the series (2 ≤N≤ 500000 );
The second act is a nonstrictly monotonic increasing number of N integers. The value range of a positive integer is [0, 500000].
Output:
Each group of test data outputs a positive integer, that is, the minimum number of operations on this series.
Sample Input
27 32 2 3 4 4 5 56 20 3 3 4 8 9
Sample output
35