Cod sursa(job #1745344)

Utilizator fanache99Constantin-Buliga Stefan fanache99 Data 21 august 2016 17:42:27
Problema Zombie Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.58 kb
#include <fstream>
#include <cstring>

using namespace std;

ifstream cin("zombie.in");
ofstream cout("zombie.out");

const int MAXN = 1000000;

int v[1 + MAXN];

int main() {
    int d, n, k;
    cin >> d >> n >> k;
    for (int i = 1; i <= n; i++)
        cin >> v[i];
    long long answer = 0;
    for (int i = 1, j = 1; i <= n; i++) {
        while (j < n && v[j + 1] - v[i] <= d)
            j++;
        if (j - i >= k) {
            answer += k;
            i = j;
        }
        else
            answer++;
    }
    cout << answer;
    return 0;
}