Cod sursa(job #2197587)

Utilizator mihai50000Mihai-Cristian Popescu mihai50000 Data 22 aprilie 2018 15:34:10
Problema Zombie Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.43 kb
#include <fstream>
using namespace std;
ifstream f("zombie.in");
ofstream g("zombie.out");
int cost, s;
const int NMAX = 1e6 + 5;
int a[NMAX];
int main()
{
	int d, n, k;
	f >> d >> n >> k;
	for(int i = 1; i <= n; i++)
		f >> a[i];
	int i = 1;
	while(i <= n)
	{
		int c = a[i];
		if(i == n)
			cost++;
		else
		{
			int j = i + 1;
			while(j <= n && a[j] - a[i] < d)
					j++;
			cost += min(k, j - i);
			i = j - 1;
		}
		i++;
	}
	g << cost;
}