#C8807. Maximum Sum Subarray of Fixed Size
Maximum Sum Subarray of Fixed Size
Maximum Sum Subarray of Fixed Size
Given an array of integers and an integer \(K\), the task is to find the maximum sum of any contiguous subarray of size \(K\). Specifically, for an array \(A = [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 array is empty, or if \(K\) is non-positive, or if \(K > n\) (where \(n\) is the length of the array), the output should be 0.
inputFormat
The input is read from stdin and consists of two lines:
- The first line contains space-separated integers representing the elements of the array.
- The second line contains a single integer \(K\), the size of the subarray.
outputFormat
Output the maximum sum of any contiguous subarray of size \(K\) to stdout. If no valid subarray exists, output 0.
## sample100 200 300 400
2
700