#K5731. Maximum Sum Subarray of Size K
Maximum Sum Subarray of Size K
Maximum Sum Subarray of Size K
You are given an array A of n integers and a positive integer K. Your task is to find the maximum sum of any contiguous subarray of size K.
If it is not possible to form a subarray of size K (i.e. when n < K), print -1.
The sum of a subarray starting at index \(i\) can be expressed as: \(S = \sum_{j=i}^{i+K-1} A_j\).
inputFormat
The first line contains two integers n and K separated by a space.
The second line contains n space-separated integers representing the elements of the array.
outputFormat
Output a single integer which is the maximum sum of any contiguous subarray of size K, or -1 if such a subarray does not exist.
## sample4 2
100 200 300 400
700