#P10093. Maximize Happiness of Gifts
Maximize Happiness of Gifts
Maximize Happiness of Gifts
Wowa has n gifts, each with a happiness value. He needs to select two indices l and r satisfying \(1 \leq l \leq r \leq n\) and \(r-l+1 \geq k\). The selected consecutive gifts (from the l-th to the r-th gift) will yield him a total happiness equal to the sum of their happiness values. Note that any gift given to his sister is not included in this calculation.
Your task is to help him choose the segment such that the sum of happiness values is maximized.
inputFormat
The first line contains two integers n and k (1 ≤ n, k ≤ 10^5). The second line contains n integers, where the i-th integer represents the happiness value of the i-th gift. The values can be negative, zero, or positive.
It is guaranteed that there is at least one segment satisfying \(r-l+1 \geq k\).
outputFormat
Output a single integer representing the maximum total happiness that Wowa can get from a contiguous segment of gifts satisfying the conditions.
sample
5 2
1 2 3 -2 5
9