#K66357. Maximum Sum Subarray

    ID: 32402 Type: Default 1000ms 256MiB

Maximum Sum Subarray

Maximum Sum Subarray

You are given an array of n integers and an integer k. Your task is to find the maximum sum of any contiguous subarray of size k.

Formally, given an array \(a_1, a_2, \ldots, a_n\) and an integer k, you need to determine: \[ \max_{1 \leq i \leq n-k+1} \left( \sum_{j=i}^{i+k-1} a_j \right) \]

You should implement an efficient solution that works well even for large arrays.

inputFormat

The input is read from standard input and has the following format:

n k
a1 a2 a3 ... an

Here, the first line contains two integers n (the number of elements) and k (the size of the subarray), and the second line contains n integers separated by spaces.

outputFormat

The output is a single integer printed to standard output, which is the maximum sum of any contiguous subarray of size k.

## sample
8 3
1 2 3 -2 5 -1 1 2
6