#C10992. Maximum Sweetness Segment

    ID: 40258 Type: Default 1000ms 256MiB

Maximum Sweetness Segment

Maximum Sweetness Segment

You are given an array of n integers representing the sweetness values of cakes, and an integer m. Your task is to determine the maximum total sweetness obtainable by choosing a contiguous segment of cakes of length m.

Formally, given an array \(a_0, a_1, \dots, a_{n-1}\) and an integer \(m\), compute \[ \max_{0 \le i \le n-m} \left( \sum_{j=i}^{i+m-1} a_j \right). \]

This problem can be efficiently solved using a sliding window technique.

inputFormat

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

  1. The first line contains two space-separated integers n and m where n is the number of cakes and m is the length of the segment.
  2. The second line contains n space-separated integers representing the sweetness values of the cakes.

outputFormat

Output to standard output (stdout) a single integer: the maximum possible sum of sweetness values of any contiguous segment of length m.

## sample
5 2
1 2 3 4 5
9