Codeforces Round #476 (Div. 2) [Thanks, Telegram!] D. Single-use Stones

D. Single-use Stones
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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?

Input

The first line contains two integers ww and ll (1l<w1051≤l<w≤105) — the width of the river and the maximum length of a frog's jump.

The second line contains w1w−1 integers a1,a2,,aw1a1,a2,…,aw−1 (0ai1040≤ai≤104), where aiai is the number of stones at the distance ii from the bank the frogs are currently at.

Output

Print a single integer — the maximum number of frogs that can cross the river.

Examples
input
Copy
10 5
0 0 1 0 2 0 0 1 0
output
Copy
3
input
Copy
10 3
1 1 1 1 2 1 1 1 1
output
Copy
3
Note

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: 0369100→3→6→9→100258100→2→5→8→100147100→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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值