Cod sursa(job #636438)

Utilizator veleanduAlex Velea veleandu Data 19 noiembrie 2011 20:17:04
Problema Zombie Scor 0
Compilator cpp Status done
Runda .com 2011 Marime 0.69 kb
#include<iostream>
#include<fstream>
#define maxn 1000001
using namespace std;
long T[maxn],Best[maxn],i,s,n,d,k,dr;
int main()
{
    ifstream in("zombie.in");
    ofstream out("zombie.out");
    in>>d>>n>>k;
    for ( i=1; i<=n; ++i)
        in>>T[i];
    n++;
    T[n]=1000000002;
    for ( s=1; s<=n; ++s)
    {

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

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