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

【Link】 I am the link, click on me :)【Title】


enter question here

【answer】


In all intervals of length L, the minimum value of the number of stones is
k, and the interval from k to be l, r

Then k is the maximum number of frogs that can pass.

Suppose k is larger. For example, if it is k+1
, then all k+1 frogs
will definitely fall in the interval l, r at a certain time of length L
(this interval cannot be skipped directly)

But there are only k stones in this interval.
Therefore, only one of k+1 must fail to pass.

So there can only be at most k frogs.

Then consider the solution problem
because of the way we get k.
So every interval of length l has at least k stones.
Then the k frogs can obviously pass without stepping on the stone every time they jump.
(The i-th frog jumps to the i-th stone at the beginning, and then, every time, it jumps to the next k-th stone, so that it will not repeat the stone walk)

So the k frogs can go to the other side, and k is the largest.

【Code】

#include <bits/stdc++.h>
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
using namespace std;

const double pi = acos(-1);
const int dx[4] = {0,0,1,-1};
const int dy[4] = {1,-1,0,0};

const int N = 1e5;

int w,l,a[N+10];

int main(){
    #ifdef LOCAL_DEFINE
        freopen("rush_in.txt", "r", stdin);
    #endif
    ios::sync_with_stdio(0),cin.tie(0);
    cin >> w >> l;
    rep1(i,1,w-1){
        cin >> a[i];
        a[i]+=a[i-1];
    }
    a[w]+=a[w-1]+1;
    //x[i+k]-x[i]<=l
    //i

    int ans = 1e9+7;
    for (int i = l;i<w;i++){
        ans = min(ans,a[i]-a[i-l]);
    }
    cout<<ans<<endl;
    return 0;
}

Guess you like

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