#C9597. Minimum Median Subarray
Minimum Median Subarray
Minimum Median Subarray
Given an array of n integers and an integer k, your task is to find the starting index of a contiguous subarray of length k whose median is the minimum among all k-length subarrays.
The median of a sorted array of length L is defined as follows:
- If L is odd, \(median = a_{\lfloor L/2 \rfloor}\).
- If L is even, \(median = \frac{a_{L/2 - 1} + a_{L/2}}{2}\).
In case of ties, choose the subarray with the smallest starting index.
inputFormat
The input is given from standard input (stdin) and consists of two lines:
- The first line contains two space-separated integers n and k, where n is the number of elements in the array and k is the length of the subarray.
- The second line contains n space-separated integers representing the array elements.
outputFormat
Output a single integer representing the starting index (0-indexed) of the subarray of length k that has the minimum median value.
## sample6 3
1 3 4 2 5 6
1