Problem Description
A group of peanuts live in a one-dimensional world. To celebrate the commencement of a new peanut civilisation, they have decided to organise a party! However, there is a problem. There are tons and tons of strawberries sprouting all over the one-dimensional world, and peanuts for some reason hate strawberries!
The one-dimesional world is split up into N segments. Each segment of land will have a certain number of strawberries growing on it. The party area would span a length of L such segments. The peanuts want to pick a section of L consecutive segments to hold their party such that the number of strawberries on that section is minimised. Help the peanuts calculate the minimum number of strawberries that are growing on their party land.
Your program is required to implement the following functions:
- int minStrawberries(int N, int L, int A[]), where A[] is an array containing the number of strawberries growing on each segment.
Limits
For all subtasks:
L <=
N,
Ai <= 1 000
Subtask 1 (37%): 1 <=
N <= 1 000
Subtask 2 (63%): 1 <=
N <= 1 000 000
Sample Input 1
5 3
2 3 1 4 5
Sample Output 1
6
Explanation for Sample 1
The section of length 3 that contains the least number of strawberries among [2, 3, 1, 4, 5] is [2, 3, 1], containing 6 strawberries.