#K34252. Maximum Entertainment Sum
Maximum Entertainment Sum
Maximum Entertainment Sum
You are given an integer n, an integer k, and n integers representing the entertainment values at different destinations. Your task is to find the maximum sum of entertainment values for any k consecutive destinations.
In mathematical terms, given an array \(a_1, a_2, \dots, a_n\) and an integer \(k\), find the maximum value of \(\sum_{i=j}^{j+k-1} a_i\) over all valid \(j\) (with \(1 \leq j \leq n-k+1\)).
This problem can be efficiently solved using a sliding window technique.
inputFormat
The first line contains two integers n and k (the number of destinations and the number of consecutive destinations to consider).
The second line contains n space-separated integers representing the entertainment values at each destination.
outputFormat
Output a single integer, the maximum sum of entertainment values for any k consecutive destinations.
## sample6 3
1 2 5 1 3 2
9