Cod sursa(job #636823)

Utilizator AndrewTheGreatAndrei Alexandrescu AndrewTheGreat Data 20 noiembrie 2011 00:03:17
Problema Zombie Scor 30
Compilator cpp Status done
Runda .com 2011 Marime 1.13 kb
#include <fstream>
#include <iostream>

using namespace std;

const int nmax = 1000010;
int A[nmax], B[nmax];

inline int bin(int v)
{
    int i, x = 0;
    for(i = 1; A[i] <= v; i <<= 1);
    for(i >>= 1; i > 0; i >>= 1)
        if(A[i + x] <= v)
            x += i;
    return x;
}

const int DIM = 1 << 13;
int poz = DIM - 1;
char buf[DIM];
int X;

inline int nr()
{
    X = 0;
    while(!isdigit(buf[poz]))
        if(++poz == DIM)
            fread(buf, sizeof(char), DIM, stdin), poz = 0;

    while(isdigit(buf[poz]))
    {
        X = X * 10 + buf[poz] - '0';

        if(++poz == DIM)
            fread(buf, sizeof(char), DIM, stdin), poz = 0;
    }
    return X;
}

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

    int D, N, K, i, ind;
    D = nr();N = nr();K = nr();
    for(i = 1; i <= N; i++)
        A[i] = nr();

    B[1] = 1;
    for(i = 2; i <= N; i++)
    {
        B[i] = B[i - 1] + 1;
        ind = bin(A[i] - D);
        if(B[i] > B[ind] + K)
            B[i] = B[ind] + K;
    }

    printf("%d\n", B[N]);
    return 0;
}