Cod sursa(job #2412390)

Utilizator Iulia25Hosu Iulia Iulia25 Data 22 aprilie 2019 10:51:44
Problema Zombie Scor 100
Compilator cpp-64 Status done
Runda problemegogule Marime 0.39 kb
#include <fstream>

using namespace std;

ifstream fin ("zombie.in");
ofstream fout ("zombie.out");

int d, n, k, ans, a[1000005];

int main()  {
  fin >> d >> n >> k;
  for (int i = 1; i <= n; ++i)
    fin >> a[i];
  int st = 1, dr = 0;
  while (st <= n)  {
    dr = st + 1;
    while (a[dr] - a[st] < d && dr <= n)
      ++dr;
    ans += min(k, dr - st);
    st = dr;
  }
  fout << ans;
  return 0;
}