Cod sursa(job #887716)

Utilizator superman_01Avramescu Cristian superman_01 Data 24 februarie 2013 00:49:08
Problema Zombie Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.99 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-1))
 
        {
             
			int nr=0;
            int numb=Q.size();     
            while(Q.back()-Q.front() >= d)
                Q.pop(),nr++;
             if(nr>=k)
				 cost+=k;
			 else
				 cost+=numb-nr;
			
			
             
        }           
         
         
         
         
    }
    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;
     
     
}