Cod sursa(job #636006)

Utilizator cristianalex81Cristian Alexandru cristianalex81 Data 19 noiembrie 2011 16:16:08
Problema Zombie Scor 100
Compilator cpp Status done
Runda .com 2011 Marime 0.89 kb
#include <fstream>

using namespace std;

int main()
{
    ifstream f("zombie.in");
    ofstream g("zombie.out");
    int n,d,k,x,i;
    int seq_start,seq_length,total;
    f>>d>>n>>k;
    //ini
    f>>seq_start; //first seq start is the enter of the first zombie
    seq_length = 1;//first seq is the first zombie
    total = 0;
    d--;
    for (i=1;i<n;i++)
    {
        f>>x;
        if ((x-seq_start)<d) //more zombies can enter the aley
            seq_length ++;
        else
        {
            if (seq_length>k)
                total += k;
            else
                total += seq_length;
            seq_start = x; //reset the sequence
            seq_length = 1; //reset the length
        }
    }
    //add the last sequence
    if (seq_length>k)
        total += k;
    else
    total += seq_length;
    //print the rezult
    g<<total<<"\n";
    f.close();
    g.close();
    return 0;
}