#C14850. Maximum Subarray Sum of Fixed Length
Maximum Subarray Sum of Fixed Length
Maximum Subarray Sum of Fixed Length
Given an array of n integers and an integer k, your task is to compute the maximum possible sum of any contiguous subarray of length k. If the length of the array is less than k, output 0.
You are required to use a sliding window technique. Mathematically, you need to compute:
\[ \max_{0 \leq i \leq n-k} \sum_{j=i}^{i+k-1} \text{nums}[j] \]
If \( n < k \), the result is defined as 0.
inputFormat
The first line contains two space-separated integers: n (the number of elements in the array) and k (the length of the subarray). The second line contains n space-separated integers representing the array elements.
outputFormat
Output a single integer, the maximum sum of any contiguous subarray of length k. Output 0 if the array length is less than k.
## sample9 4
1 4 2 10 23 3 1 0 20
39