#C7848. Maximum Berries Collection

    ID: 51764 Type: Default 1000ms 256MiB

Maximum Berries Collection

Maximum Berries Collection

You are given T test cases. In each test case, you are provided with an integer N representing the number of years, and an integer Y which indicates the number of consecutive years. You also have an array of N integers representing the number of berries collected in each year.

Your task is to determine the maximum number of berries that can be collected over any span of Y consecutive years in each test case.

The problem can be formalized as follows:

Given an array \(a_1, a_2, \ldots, a_N\) and an integer \(Y\), find: \[ \max_{1 \leq i \leq N-Y+1} \left(\sum_{j=0}^{Y-1} a_{i+j}\right) \]

Note that if \(Y = N\), the answer is simply the sum of all elements in the array.

inputFormat

The input is read from stdin and has the following format:

T
N1 Y1
a1 a2 ... aN1
N2 Y2
a1 a2 ... aN2
...
NT YT
a1 a2 ... aNT

Where:

  • T is the number of test cases.
  • For each test case, the first line contains two space-separated integers \(N\) and \(Y\).
  • The second line contains \(N\) space-separated integers representing the berry counts for each year.

outputFormat

For each test case, output the maximum number of berries that can be collected over any span of \(Y\) consecutive years. Each result should be printed on a new line to stdout.

## sample
2
5 2
1 2 3 4 5
7 3
4 0 3 2 5 6 2
9

13

</p>