Cod sursa(job #887714)

Utilizator superman_01Avramescu Cristian superman_01 Data 24 februarie 2013 00:43:45
Problema Zombie Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.97 kb
#include<cstdio>
#include<fstream>
#include<queue>
 
 
#define NMAX 1000005
 
using namespace std;
 
queue <int> Q;
ifstream f("zombie.in");
ofstream g("zombie.out");
int d,n,k;
int cost;
int dist[NMAX];
int x;
 
void read ( void )
{
    f>>d>>n>>k;
    cost=0;
    for(int i(1); i <= n ; ++i )
    {
        f>>x;
        Q.push(x);
        if(Q.back()-Q.front() >= d)
 
        {
             
            if(Q.size() > k )
                cost+=k;
            else
                 
            while(Q.back()-Q.front() >= d)
                Q.pop(),cost++;
             
             
        }           
         
         
         
         
    }
    if(Q.size() )
        if(Q.size() > k)
            cost+=k;
        else
            cost+=Q.size();
    f.close();
}
 
 
void write ( void )
{
     
    g<<cost;
    g.close();
}
 
 
int main()
{
    read();
    //solve();
    write();
    return 0;
     
     
}