A lot of frogs want to cross a river. A river is ww units width, but frogs can only jump ll units long, where l<wl<w. Frogs can also jump on lengths shorter than ll. but can't jump longer. Hopefully, there are some stones in the river to help them.
The stones are located at integer distances from the banks. There are aiai stones at the distance of ii units from the bank the frogs are currently at. Each stone can only be used once by one frog, after that it drowns in the water.
What is the maximum number of frogs that can cross the river, given that then can only jump on the stones?
The first line contains two integers ww and ll (1≤l<w≤1051≤l<w≤105) — the width of the river and the maximum length of a frog's jump.
The second line contains w−1w−1 integers a1,a2,…,aw−1a1,a2,…,aw−1 (0≤ai≤1040≤ai≤104), where aiai is the number of stones at the distance ii from the bank the frogs are currently at.
Print a single integer — the maximum number of frogs that can cross the river.
10 5 0 0 1 0 2 0 0 1 0
3
10 3 1 1 1 1 2 1 1 1 1
3
In the first sample two frogs can use the different stones at the distance 55, and one frog can use the stones at the distances 33 and then 88.
In the second sample although there are two stones at the distance 55, that does not help. The three paths are: 0→3→6→9→100→3→6→9→10, 0→2→5→8→100→2→5→8→10, 0→1→4→7→100→1→4→7→10.
#include<bits/stdc++.h>
using namespace std;
int sum[100005];
int main()
{
int w,l;scanf("%d%d",&w,&l);
for(int i=1;i<w;i++)
{
int x;scanf("%d",&x);
sum[i]=sum[i-1]+x;
}
int ans=sum[l];
for(int i=l+1;i<w;i++)
ans=min(ans,sum[i]-sum[i-l]);
printf("%d\n",ans);
return 0;
}