Maximum Window Sum

View as PDF

Submit solution


Points: 100
Time limit: 2.0s
Memory limit: 256M

Author:
Problem type

Given an array a of length n and an integer k, find the maximum possible sum of a contiguous subarray of length exactly k.

Remember that a subarray is a contiguous section of the array.

Input

The first line contains two integers n and k.

The second line contains n integers a_1, a_2, \dots, a_n.

Output

Print a single integer: the maximum sum of any contiguous subarray of length exactly k.

Constraints

  • 1 \le k \le n \le 10^5
  • -10^3 \le a_i \le 10^3

Example 1

Input
5 3
1 -2 3 -4 5
Output
4
Explanation

The length-3 subarrays have sums 2, -3, and 4, so the answer is 4.

Example 2

Input
8 3
-512 750 27 -532 -940 781 -449 278
Output
610

Comments

There are no comments at the moment.