Cod sursa(job #2015699)

Utilizator victoreVictor Popa victore Data 27 august 2017 00:31:25
Problema Zombie Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.92 kb
#include<cstdio>

using namespace std;

const int nmax=1e6+5;

int st[nmax],top,bot=1,d,n,k;


int main()
{
    freopen("zombie.in","r",stdin);
    freopen("zombie.out","w",stdout);
    int i,j;
    scanf("%d%d%d",&d,&n,&k);
    int x;
    long long cost=0;
    for(i=1;i<=n;++i)
    {
        scanf("%d",&x);
        if(bot > top)
            st[++top] =x;
        else
        {
            if(x - st[bot] >= d)
            {
                //tre sa scot
                if(top-bot+1 < k)
                    cost = cost + top-bot+1;

                else
                    cost = cost +k;
                st[++top]=x;
                bot=top;
            }
            else
                st[++top]=x;
        }
    }
    if(top-bot+1 > 0)
    {
        if(top-bot+1 < k)
            cost = cost + top-bot+1;
        else
            cost = cost + k;
    }
    printf("%lld",cost);
}