#K52572. Maximum Fruits in K Consecutive Sections
Maximum Fruits in K Consecutive Sections
Maximum Fruits in K Consecutive Sections
You are given an integer n representing the number of sections in a fruit garden, an integer k, and an array of n integers where each integer denotes the number of fruits in a section. Your task is to determine the maximum number of fruits that can be collected by picking exactly k consecutive sections from the garden.
This problem is equivalent to finding the maximum sum of any contiguous subarray of length k. You can assume that 1 ≤ k ≤ n.
inputFormat
The input is given in the following format:
- A single integer n representing the number of sections.
- A single integer k representing the number of consecutive sections to pick.
- A line containing n space-separated integers, where each integer represents the number of fruits in that section.
outputFormat
Output a single integer: the maximum number of fruits that can be collected from any contiguous group of exactly k sections.
## sample5
3
2 1 4 5 3
12
</p>