Pagini recente » Cod sursa (job #2822950) | Cod sursa (job #2463345) | Cod sursa (job #503952) | Cod sursa (job #2241292) | Cod sursa (job #636812)
Cod sursa(job #636812)
#include <fstream>
#include <iostream>
using namespace std;
const int nmax = 1000010;
int A[nmax], B[nmax];
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];
void nr(int &x)
{
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;
}
}
int main()
{
freopen ("zombie.in", "r", stdin);
freopen ("zombie.out", "w", stdout);
int D, N, K, i, ind;
nr(D);nr(N);nr(K);
for(i = 1; i <= N; i++)
nr(A[i]);
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;
}