#C6969. Maximum Sum of a Fixed-Size Contiguous Subarray
Maximum Sum of a Fixed-Size Contiguous Subarray
Maximum Sum of a Fixed-Size Contiguous Subarray
You are given an array of n integers and an integer k. Your task is to find the maximum sum of any contiguous subarray of size exactly k.
More formally, given an array A of length n, you need to compute:
\(\max_{0 \leq i \leq n-k}\left(\sum_{j=i}^{i+k-1} A_j\right)\)
You are required to solve this problem using the sliding window technique to ensure that the solution is efficient.
inputFormat
The first line contains two integers n and k separated by a space, where n is the number of elements in the array and k is the size of the subarray.
The second line contains n integers separated by spaces representing the elements of the array.
Note: It is guaranteed that n and k satisfy appropriate constraints so that a contiguous subarray of size k exists (i.e. n \geq k).
outputFormat
Output a single integer representing the maximum sum of any contiguous subarray of length k.
## sample7 3
1 2 3 4 5 6 7
18