#K42502. Maximum Sliding Window Sum with Adjustments
Maximum Sliding Window Sum with Adjustments
Maximum Sliding Window Sum with Adjustments
You are given an array of integers of size n
, a sliding window size k
, and an integer m
which indicates the maximum number of allowed adjustments. Although you are allowed to adjust at most m
elements of the array, in this problem the optimal strategy always is to choose the contiguous subarray of length k
that already yields the maximum sum without any adjustments.
Your task is to compute the maximum sum of any contiguous subarray of size k
in the given array. Formally, if the array is represented as \(a_0, a_1, \ldots, a_{n-1}\), you need to find:
[ \max_{0 \le i \le n-k} \left(\sum_{j=0}^{k-1} a_{i+j}\right) ]
Note: The value m
is provided as part of the input but does not affect the optimal outcome for the test cases.
inputFormat
The first line of input contains three integers n
, k
, and m
separated by spaces, where \(n\) is the number of elements in the array, \(k\) is the size of the sliding window, and \(m\) represents the maximum adjustments allowed. The second line contains \(n\) integers representing the array elements, separated by spaces.
Example:
8 3 2 1 2 3 -4 -5 6 7 8
outputFormat
Output a single integer which is the maximum sum of any contiguous subarray of size k
.
Example:
21## sample
8 3 2
1 2 3 -4 -5 6 7 8
21