Cod sursa(job #3306810)

Utilizator slol003Rizea Alexandru-Gabriel slol003 Data 14 august 2025 09:46:06
Problema Zombie Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.6 kb
#include <fstream>

using namespace std;

int main() {
    ifstream fin("zombie.in");
    ofstream fout("zombie.out");
    int d, n, k, a, b, cnt, cost;
    fin >> d >> n >> k;
    fin >> b;
    cnt = 1;
    cost = 0;
    for(int i = 1; i < n; i ++) {
      fin >> a;
      if(d - (a - b) < 0) {
        if(cnt < k)
          cost = cost + cnt;
        else
          cost = cost + k;
        cnt = 1;
        b = a;
      }
      else {
        cnt ++;
      }
    }
    if(cnt < k)
          cost = cost + cnt;
        else
          cost = cost + k;
    fout << cost;
    return 0;
}