#C2447. Max Energy Collected from Trees

    ID: 45764 Type: Default 1000ms 256MiB

Max Energy Collected from Trees

Max Energy Collected from Trees

In this problem, you are given a sequence of integers representing the energy values of a series of trees. You are also provided two integers, ( n ) and ( k ), where ( n ) is the total number of trees and ( k ) is the number of consecutive trees you can choose. Your task is to determine the maximum total energy that can be collected from any contiguous segment of exactly ( k ) trees. This problem can be efficiently solved using a sliding window technique.

inputFormat

The input is read from standard input (stdin). The first line contains two space-separated integers ( n ) and ( k ). The second line contains ( n ) space-separated integers, where each integer represents the energy value of a tree.

outputFormat

Output a single integer to standard output (stdout), representing the maximum energy sum that can be obtained from any contiguous block of exactly ( k ) trees.## sample

5 2
1 2 3 4 5
9