Problem 04C. Sliding Window Sum ≡

Author:Pavel Mesenev   Time limit:2 sec
Input file:Standard input   Memory limit:256 Mb
Output file:Standard output  

Statement

A stream of n integers a0, a1, …, an − 1 arrives one at a time, together with a fixed window size k (1 ≤ k ≤ n), known in advance. For every position i with i ≥ k − 1, report the sum of the last k values seen so far: ai − k + 1 + ai − k + 2 + …  + ai.

Input format

The first line contains two integers n and k. The second line contains n space-separated integers a0… an − 1.

Output format

Print n − k + 1 lines: the sliding-window sum for i = k − 1,k,…,n − 1, in order.

Constraints

1 ≤ k ≤ n ≤ 2 ⋅ 105

 − 109 ≤ ai ≤ 109

Every printed sum fits into a signed 64-bit integer.

Sample tests

No. Standard input Standard output
1
8 3
1 2 3 4 5 6 7 8
6
9
12
15
18
21
2
5 1
-1 2 -3 4 -5
-1
2
-3
4
-5
3
4 4
10 -10 10 -10
0

0.035s 0.010s 18