#C11818. Maximize Mean Subarray

    ID: 41176 Type: Default 1000ms 256MiB

Maximize Mean Subarray

Maximize Mean Subarray

You are given an array of integers and an integer \( k \). Your task is to find the contiguous subarray of length \( k \) that has the highest mean value, and output that subarray.

The mean of a subarray of length \( k \) is defined as:

[ \text{mean} = \frac{1}{k} \sum_{i=1}^{k} a_i ]

Since \( k \) is fixed, finding the subarray with the maximum mean is equivalent to finding the subarray with the maximum sum.

If \( k \) is greater than the number of elements in the array, output an empty line.

inputFormat

The input is given via standard input (stdin) and consists of two lines:

  • The first line contains two 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 elements of the array.

outputFormat

Output the contiguous subarray of length \( k \) with the highest mean value as \( k \) space-separated integers on a single line. If \( k \) is greater than \( n \), output an empty line.

## sample
6 4
1 12 -5 -6 50 3
12 -5 -6 50