cf Single-use Stones(水题)

贪心的想法,希望把青蛙们尽可能的往前堆,实现稍微有一点麻烦(我太垃圾了)

#include <iostream>
using namespace std;
#define debug(x) std::cerr << #x << " = " << (x) << std::endl
typedef long long LL;
const int MAXN = 1e5+17;
const int MOD = 998244353;
int a[MAXN],f[MAXN];
int main(int argc ,char const *argv[])
{
    #ifdef noob
    freopen("Input.txt","r",stdin);freopen("Output.txt","w",stdout);
    #endif  
    int n,l,cur = 0,lm=0;
    cin>>n>>l;
    n--;
    for (int i = 0; i < n; ++i)
    {
        cin>>a[i];
        if(i<l) cur+=a[i],f[i]=a[i];
    }
    for (int i = l; i < n; ++i)
    {
        if(a[i]<f[i-l]) 
        {
            cur -= f[i-l]-a[i];
            f[i] = a[i]; 
            lm++;
        }
        else
        {
            int tmp = a[i];
            while(lm<i)
            {
                if(tmp>=f[lm])
                {
                    tmp -= f[lm];
                    f[lm] = 0;
                    lm++;
                }
                else
                {
                    f[lm] -= tmp;
                    tmp = 0;
                    break;
                }
            }
            f[i] = a[i]-tmp;
        }
    }
    cout<<cur<<endl;
    return 0;   
}

猜你喜欢

转载自blog.csdn.net/m0_37802215/article/details/80148875