Cod sursa(job #636234)

Utilizator idomiralinIdomir Alin idomiralin Data 19 noiembrie 2011 17:57:21
Problema Zombie Scor 100
Compilator cpp Status done
Runda .com 2011 Marime 1.01 kb
# include <cstdio>

using namespace std;

int d, n, k, daux, daux1, drez, ok, ct, ct1;
int a[1000005];
int main()
{int i, j;
    
    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",&a[i]);
    
    
    daux = d;
    for (i = 1; i <= n; )
    if (a[i + 1] - a[i] >= daux)
    {
         i++;
         ct++;
         daux = d;
         ok = 0;
         }
    else 
    {
         ct1 = ct + 1;
         daux1 = a[i + 1] - a[i];
         drez = daux - daux1;
         //if (a[i + 1] - a[i] >= drez) continue;
         while (a[i + 1] - a[i] < drez && i + 1 <= n)
         {
               i++;
               ct1++;
               ok = 1;
               daux1 = a[i] - a[i - 1];
               drez = drez - daux1;
               }
               i++;
         if (ok == 1) ct += k;
         if (ct1 < ct) ct = ct1; 
         }
         
    printf("%d",ct);
    
return 0;
}