#K40587. Maximal Luminous Fruit Collection

    ID: 26675 Type: Default 1000ms 256MiB

Maximal Luminous Fruit Collection

Maximal Luminous Fruit Collection

You are given N luminous trees, called Luminarias, arranged in a straight line. Each Luminaria drops fruits at a rate given in the array ( R ), where the ( i^{th} ) element represents the number of luminous fruits dropped per hour by that Luminaria. Your task is to choose a segment of K consecutive Luminarias such that the total number of fruits collected in one hour is maximized.

The sum for a segment starting at index ( i ) is defined as: [ S = \sum_{j=i}^{i+K-1} R[j] ]

You need to output the maximum ( S ) value possible.

Constraints:

  • 1 ≤ K ≤ N ≤ 105
  • 0 ≤ R[i] ≤ 104

inputFormat

The input is read from the standard input (stdin) and consists of two lines:

  • The first line contains two space-separated integers: N (the number of Luminarias) and K (the number of consecutive Luminarias to consider).
  • The second line contains N space-separated integers representing the array \( R \), where each integer denotes the fruit drop rate per hour for each Luminaria.

outputFormat

Output a single integer to the standard output (stdout), which is the maximum number of luminous fruits that can be collected in one hour from any segment of K consecutive Luminarias.## sample

6 3
10 20 30 40 50 60
150

</p>