#C6774. Find Subarray with Target Average
Find Subarray with Target Average
Find Subarray with Target Average
Given an array of integers and two parameters k and target, determine whether there exists a contiguous subarray of length k whose average equals target. In other words, you need to check if there exists a subarray whose sum is equal to \(target \times k\). If such a subarray exists, output its starting index (0-indexed); otherwise, output -1.
inputFormat
The input is read from stdin and consists of four lines:
1. An integer n representing the number of elements in the array.
2. n space-separated integers representing the array elements.
3. An integer k, the length of the subarray to be considered.
4. A number target which can be an integer or a floating-point number, representing the desired average.
outputFormat
The output should be written to stdout and is a single integer: the starting index (0-indexed) of the subarray whose average equals target. If no such subarray exists, output -1.
## sample6
1 2 3 4 5 6
3
4
2