#C4521. Maximum Subarray Sum

    ID: 48069 Type: Default 1000ms 256MiB

Maximum Subarray Sum

Maximum Subarray Sum

You are given several datasets. Each dataset describes an array of integers and a fixed subarray length. Your task is to find the maximum possible sum of any contiguous subarray of exactly L elements for each dataset.

More formally, for each dataset, you are given two integers \(N\) and \(L\) and an array \(a_1, a_2, \dots, a_N\). You need to compute:

[ \max_{1 \leq i \leq N-L+1} \left(\sum_{j=i}^{i+L-1}a_j\right) ]

The input consists of multiple datasets, and the end of input is indicated by a line containing a single zero.

inputFormat

The input is read from stdin and consists of multiple datasets. Each dataset has the following format:

  • The first line contains two integers \(N\) and \(L\) where \(N\) is the number of elements in the array and \(L\) is the length of the subarray.
  • The second line contains \(N\) space-separated integers.

A line with the single integer 0 marks the end of input.

outputFormat

For each dataset, output a single line to stdout containing one integer: the maximum subarray sum for a subarray of length \(L\).

## sample
5 3
1 2 3 4 5
8 4
-1 -2 -3 -4 1 2 3 4
0
12

10

</p>