#C6007. Maximum Distance Over k Days

    ID: 49720 Type: Default 1000ms 256MiB

Maximum Distance Over k Days

Maximum Distance Over k Days

You are given the number of days n, a positive integer k, and a list of distances representing the distance run on each day. Your task is to determine the maximum total distance run over any k consecutive days.

In mathematical notation, if the distances are given as an array \(d_1, d_2, \dots, d_n\), you need to compute:

\[ \max_{1 \leq i \leq n-k+1} \left(\sum_{j=i}^{i+k-1} d_j\right) \]

It is guaranteed that \(1 \leq k \leq n\). Read the input from stdin and write the result to stdout.

inputFormat

The input is read from stdin and consists of two lines:

  • The first line contains two integers n and k separated by a space, where n is the number of days and k is the number of consecutive days to consider.
  • The second line contains n space-separated integers, representing the distance run on each day.

For example:

10 3
6 2 3 7 1 4 5 8 9 6

outputFormat

The output should be a single integer printed to stdout — the maximum total distance run over any k consecutive days.

For example, given the sample input above, the correct output is:

23
## sample
10 3
6 2 3 7 1 4 5 8 9 6
23