|
|||
Lanovka – The Cable CarThere are N peaks in the Vector Vista Mountains. We want to install cable car columns on K adjacent peaks so that if the largest height of the cable car (peak + column) is H, then on the other peaks the heights should be H – 1, H – 2, …, H – K + 1, so that the cable car continues to go up smoothly. The cable car always starts from the right and goes to the left. We can achieve this by increasing the height of the cable car columns by 1 unit. By how many minimum units must the heights of columns be increased in total in order to create a cable car of length K? Input SpecificationThe first line of the input contains the number of test cases T (1 ≤ T ≤ 20). This is followed by two lines for each test case. The first line contains the number of peaks N (1 ≤ N ≤ 200 000) and the length of the cable car K (1 ≤ K ≤ N). The second line contains N natural numbers Hi (1 ≤ i ≤ N), the heights of the mountain peaks (1 ≤ Hi ≤ 1 000 000 000). Output SpecificationFor each test case, print a single number on a line by itself: the minimum number of units. Sample Input
Output for Sample Input
Explanation
The 3 possible cable cars are:
The minimum of the total differences is 4. |
|||
University of Debrecen; Faculty of Informatics; v. 09/30/2024 |