题目链接:http://codeforces.com/problemset/problem/965/D
题意:
w表示河的宽度,l表示青蛙所能跳的最远的距离,第二行的w-1个元素表示离河岸为i的地方有a[i]个石头,一
个石头被踩两次,问最多有多少只青蛙可以跳到河对岸
题解:
因为最多能跳过几只青蛙,是由落脚点的数目的最小值决定的,所以他的问题实际上就是在[i,i+l],i∈[l,w-1],
最少的石头数目是多少
参考博客:https://www.cnblogs.com/visualVK/p/8994154.html
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
const int inf=0x3f3f3f3f;
int a[maxn],sum[maxn];
int main()
{
int W,L;
int ans=inf;
scanf("%d%d",&W,&L);
for(int i=1;i<W;i++){
scanf("%d",&a[i]);
sum[i]=sum[i-1]+a[i];
}
for(int i=L;i<W;i++){
ans=min(ans,sum[i]-sum[i-L]);
}
printf("%d\n",ans);
return 0;
}