#P17386. [PacNW 2025] Kth King
[PacNW 2025] Kth King
Problem Description
Reyjrland is represented by an integer array of length , where each element is the value of one city. For any array of length at least , let be its th-largest value.
The cities represent the likeness of the th king if is the same for every contiguous subarray of whose length is at least . A subarray is obtained by deleting zero or more elements from the beginning and zero or more elements from the end; an array is a subarray of itself.
Each day, the king may increase or decrease one city value by . For every from through , find the minimum number of days needed to modify the original array so that it represents the likeness of the th king. Modifications for one value of do not carry over to another: the array is reset to its original values each time.
Input Format
The first line contains an integer ().
Each of the next lines contains one integer ().
Output Format
Output lines. Line contains the minimum number of days needed for the th king.
3
2
3
1
2
1
0
4
1000000000
1
1000000000
1
1999999998
999999999
0
0