#K776. Maximum Sum Subarray
Maximum Sum Subarray
Maximum Sum Subarray
Given an array of integers and an integer \(k\), your task is to find the contiguous subarray of length \(k\) with the maximum possible sum. Formally, if the array is \(a_1, a_2, \dots, a_n\), you need to compute \(\max_{1 \leq i \leq n-k+1} \sum_{j=i}^{i+k-1} a_j\). If the input is invalid (i.e., the array is empty, \(k \le 0\), or \(k > n\)), the output should be 0.
inputFormat
The input is given via standard input (stdin). The first line contains two space-separated integers \(n\) and \(k\), where \(n\) is the number of elements in the array and \(k\) is the length of the subarray. The second line contains \(n\) space-separated integers representing the array elements.
outputFormat
Output a single integer to standard output (stdout) representing the maximum sum of any contiguous subarray of length \(k\).
## sample6 3
2 1 5 1 3 2
9