#K42422. Subarray Minimum Transformation
Subarray Minimum Transformation
Subarray Minimum Transformation
Given an array of n integers and an integer x, transform the array such that for every index i (0-indexed), the element at i is replaced by the minimum element among the next x elements. If there are fewer than x elements following index i, consider only the available elements. For the last element of the array, output -1
.
Formally, define the transformed array ans as follows:
$$ans[i] = \begin{cases} \min_{j=i+1}^{\min(i+x,\,n-1)} arr[j] & \text{if } i < n-1, \\ -1 & \text{if } i = n-1. \end{cases} $$Your task is to read the input from stdin, perform the transformation, and output the result to stdout.
inputFormat
The first line contains two integers n
and x
, where n
is the number of elements in the array and x
is the number of subsequent elements to consider for each position.
The second line contains n
space-separated integers representing the array.
outputFormat
Output a single line containing the transformed array with space-separated integers.
## sample5 2
4 7 2 8 9
2 2 8 9 -1