Cod sursa(job #636548)

Utilizator veleanduAlex Velea veleandu Data 19 noiembrie 2011 21:11:56
Problema Zombie Scor 0
Compilator cpp Status done
Runda .com 2011 Marime 1.24 kb
#include<iostream>
#include<fstream>
#include<stdio.h>
#define maxn 1000010
using namespace std;
long long T[maxn],Best[maxn];
long long i,s,n,d,k,dr;
#define T (T + 100)
#define Best (Best + 100)



FILE* fin=fopen("zombie.in","r");
const unsigned maxb=8192;
char buf[maxb];
unsigned ptr=0;
 inline unsigned getInt()
 {  unsigned nr=0;
 while(buf[ptr]<'0'||'9'<buf[ptr])
 if(++ptr>=maxb)
 fread(buf,maxb,1,fin),ptr=0;  while('0'<=buf[ptr]&&buf[ptr]<='9'){   nr=nr*10+buf[ptr]-'0';   if(++ptr>=maxb)    fread(buf,maxb,1,fin),ptr=0;  }  return nr; }

int main()
{
    freopen("zombie.out", "w", stdout);

    d=getInt();
    n=getInt();
    k=getInt();
    //cin>>d>>n>>k;
    //cout<<d<<" "<<n<<" "<<k<<"\n";
    for ( i=1; i<=n; ++i)
        T[i]=getInt();
        //cin>>T[i];
    n++;
    T[n]=1000000002;
    for ( s=1; s<=n; ++s)
    {

        while ( T[s]+d-1>=T[dr+1] && dr<=n)
        {
            dr++;
           // cout<<T[s]+d-1<<" "<<T[dr]<<" "<<dr<<"\n";
        }
        //out<<dr<<"@\n";

        if ( (Best[dr+1]>Best[s]+k || Best[d+1]==0 ) && (Best[dr+1]+k<=s) )
            Best[dr+1]=Best[s]+k;
        if ( (Best[s+1]>Best[s]+1 || Best[s+1]==0) && (Best[s]+1<=s) )
            Best[s+1]=Best[s]+1;
    }
    cout<<Best[n]<<"\n";
    return 0;
}