#K50762. Sliding Window Sums
Sliding Window Sums
Sliding Window Sums
You are given an array of n integers and an integer k representing the size of a sliding window. Your task is to compute the sum of each consecutive subarray (window) of length k in the array.
The sum for the window starting at index i is defined as:
\( S_i = \sum_{j=i}^{i+k-1} a_j \)
for \( i = 0, 1, \ldots, n-k \). Print the resulting sums in order, separated by a space.
It is guaranteed that \( 1 \leq k \leq n \).
inputFormat
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 size of the sliding window.
The second line contains n space-separated integers representing the array elements.
outputFormat
Output a single line containing the sums of each sliding window of size k in the array, separated by a space.
## sample5 3
1 2 3 4 5
6 9 12