Cod sursa(job #1566330)

Utilizator eu3neuomManghiuc Teodor-Florin eu3neuom Data 11 ianuarie 2016 23:25:03
Problema Zombie Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.61 kb
#include <bits/stdc++.h>

using namespace std;

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

int main(){
    int n, d, k, last, pos, x, cost;
    fin >> d >> n >> k >> last;
    pos = 1;
    cost = 0;
    for(int i = 2; i <= n; i++){
        fin >> x;
        if(x - last > d){
            if(i - pos >= k){
                cost += k;
            } else {
                cost += (i - pos);
            }
            last = x;
            pos = i;
        }
    }
    if(n - pos >= k){
        cost += k;
    } else {
        cost += (n - pos);
    }
    fout << cost;
    return 0;
}