Cod sursa(job #637334)

Utilizator veleanduAlex Velea veleandu Data 20 noiembrie 2011 13:50:16
Problema Zombie Scor 0
Compilator cpp Status done
Runda .com 2011 Marime 0.69 kb
#include<iostream>
#include<fstream>
#define NmaX 1000005
using namespace std;

typedef struct { long el,c; } zombie;
zombie T[NmaX];
long s,dr,k,d,n,i;
int main()
{
    ifstream in("zombie.in");
    ofstream out("zombie.out");
    in>>d>>n>>k;
    for ( i=1; i<=n; ++i)
        in>>T[i].el;
    T[1].c=1;
    for ( s=1; s<=n; ++s)
    {
        while ( T[dr+1].el<T[s].el+d && dr<n)
            dr++;
        if ( (T[dr].c>T[s].c+k-1) || (T[dr].c==0 && T[s].c+k-1<=dr) )
            T[dr].c=T[s].c+k-1;
        if ( T[s+1].c ==0 )
            T[s+1].c=T[s].c+1;
        /*for ( i=1; i<=n; ++i)
            cout<<T[i].c<<" ";
        cout<<"\n";
        cout<<dr<<" ";*/
    }
    out<<T[n].c<<"\n";
}