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

D - Single-use Stones

write picture description here
portal

Title: Frogs cross the river, it's a bit violent, Gou.

Solution: It's actually very simple. Let's think about it this way. The distance the frog moves is [ 0 , l ] , then every time the frog moves we can see it as l Such a segment is moving (jump out l We don't care about him outside), what really affects whether we can get to the other side of the river is this l Whether there are enough footholds, we find l The least foothold in the a n s .

#include<cstdio>
#include<iomanip>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<queue>
#include<limits.h>
#include<string.h>
#include<map>
#include<list>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

#define inf int(0x3f3f3f3f)
#define mod int(1e9+9)
#define eps double(1e-6)
#define pi acos(-1.0)
#define lson  root << 1
#define rson  root << 1 | 1

ll n,l;

ll a[100005];
ll sum[100005];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    memset(sum,0,sizeof(sum));
    ll ans=LONG_MAX;
    cin>>n>>l;
    for(int i=1;i<n;i++)
    {
        cin>>a[i];
        sum[i]=sum[i-1]+a[i];
    }
    for(int i=l;i<n;i++)
        ans=min(ans,sum[i]-sum[i-l]);
    cout<<ans<<endl;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325714017&siteId=291194637