Cod sursa(job #1676214)

Utilizator Alexa2001Alexa Tudose Alexa2001 Data 5 aprilie 2016 19:30:32
Problema Zombie Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.59 kb
#include <cstdio>
#include <algorithm>

using namespace std;

const int N=(1e6)+5;
int n,k,i,t[N],d[N],D;

int bs(int x)
{
     int st=1,dr=n,mij;
     while(st<=dr)
     {
         mij=((st+dr)>>1);
         if(t[mij]==x) return mij-1;
         if(t[mij]<x) st=mij+1;
         else dr=mij-1;
     }
     return dr;
}

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

    scanf("%d%d%d", &D, &n, &k);

    for(i=1; i<=n; ++i) scanf("%d", &t[i]);

    for(i=1; i<=n; ++i)
        d[i]=min( d[i-1]+1, d[bs(t[i]-D+1)]+k);

    printf("%d\n", d[n]);

    return 0;
}