#C10545. Maximum Happiness Gain

    ID: 39762 Type: Default 1000ms 256MiB

Maximum Happiness Gain

Maximum Happiness Gain

You are given n attractions with associated happiness values. A visitor wants to visit l consecutive attractions such that the total happiness gained is maximized.

Formally, you are given an array h of size n and an integer l. You need to compute:

$$\max_{0 \le i \le n - l} \left(\sum_{j=i}^{i+l-1} h_j\right)$$

It is guaranteed that n is at least l.

inputFormat

The input is provided through standard input (stdin) and contains two parts:

  1. The first line contains two integers, n and l, where n is the number of attractions and l is the number of consecutive attractions to select.
  2. The second line contains n space-separated integers representing the happiness values for each attraction.

outputFormat

Output a single integer to standard output (stdout), which is the maximum possible happiness gain over any contiguous subarray of length l.

## sample
5 3
1 2 3 4 5
12