Maximum Window Sum

View as PDF

Submit solution

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

Author:
Problem type

Problem Description

Given an array, a nonempty subarray is defined as a continuous piece of that array. More specifically, a is a subarray of b if a is the result of deleting zero or more elements from the front of b, and zero or more elements from the end.

Given an array a of length n and an integer k, what is the largest sum of a subarray of a, if the subarray has to be of size k?

Input Format

The first line of the input will be two integers, n and k. The next line of the input will consist of n integers, representing a.

Output Format

Output a single integer, the maximum sum of a subarray of a that is length k.

Constraints

n \le 1e5

k \le n

-1e3 \le a[i] \le 1e3

Sample Input 1

5 3
1 -2 3 -4 5

Sample Output 1

4

Sample Input 2

8 3
-512 750 27 -532 -940 781 -449 278

Sample Output 2

610

Comments

There are no comments at the moment.