Cod sursa(job #636957)

Utilizator thesilverhand13FII Florea Toma Eduard thesilverhand13 Data 20 noiembrie 2011 07:46:46
Problema Zombie Scor 100
Compilator cpp Status done
Runda .com 2011 Marime 0.66 kb
 # include <fstream>
 # include <algorithm>
 
 # define dim 1000005
 
 using namespace std;
 
 ifstream f("zombie.in");
 ofstream g("zombie.out");
 
 int a[ dim ];
 int n, d, k;
 int sol;
 
 void citire()
 {
	 int i;
	 f >> d >> n >> k;
	 for ( i = 1 ; i <= n ; i ++ )
		 f >> a[ i ];
 }
 
 void rezolva()
 {
	 int i = 1, nr = 0;
	
	 while ( i <= n )
	 {
		 nr = i;
		 i ++;
		 while ( a[ i ] <= a[ nr ] + d - 1 )
			 i ++;
		 
		 if ( i - nr >= k )
			 sol = sol + k;
		 else
		 {
			 sol = sol + ( i - nr );
		 }
		 
		 //g << i << " ";
	 }
	 g << sol  << "\n";
 }
 
 
 int main()
 {
	 citire();
	 rezolva();
	 return 0;
 }