#C13288. Maximum Sum of Fixed-Length Subarray
Maximum Sum of Fixed-Length Subarray
Maximum Sum of Fixed-Length Subarray
Given an array of integers \(a_1, a_2, \ldots, a_n\) and an integer \(k\), you are required to find the maximum sum of any contiguous subarray of size \(k\). Formally, you need to compute:
$$ \max_{1 \le i \le n-k+1} \sum_{j=i}^{i+k-1} a_j $$
You are expected to implement an efficient solution using a sliding window technique.
inputFormat
Input is read from 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 size of the subarray. The second line contains (n) space-separated integers representing the array elements.
outputFormat
Output to standard output (stdout) a single integer representing the maximum sum of any contiguous subarray of size (k).## sample
4 2
100 200 300 400
700