#K70227. Smallest Subarray with Minimum Sum
Smallest Subarray with Minimum Sum
Smallest Subarray with Minimum Sum
You are given an integer m and an array of integers. Your task is to find the first contiguous subarray of length m that has the smallest sum among all subarrays of that length.
Formally, if the array is represented as \(a_1, a_2, \dots, a_n\), you need to find the subarray \(a_i, a_{i+1}, \dots, a_{i+m-1}\) such that \(\sum_{j=i}^{i+m-1}a_j\) is minimal for \(1\le i\le n-m+1\). If there exist multiple subarrays with the same sum, choose the one with the smallest starting index.
inputFormat
The input consists of two lines:
- The first line contains an integer m, which is the length of the subarray.
- The second line contains a list of space-separated integers representing the array.
outputFormat
Output the subarray of length m with the smallest sum. The numbers should be printed in the same order as they appear in the array, separated by a single space.
## sample2
5 2 2 3 1
2 2