Cod sursa(job #1459242)

Utilizator laurageorgescuLaura Georgescu laurageorgescu Data 9 iulie 2015 14:40:09
Problema Zombie Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.65 kb
#include<fstream>

using namespace std;

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

const int nmax = 1000000;
int v[ nmax + 1 ];

int main() {
    int n, d, k, x;
    long long ans;

    fin >> d >> n >> k >> v[ 1 ];

    ans = 0; x = 1;
    for( int i = 2; i <= n; ++ i ) {
        fin >> v[ i ];
        if ( v[ i ] - v[ x ] >= d ) {
            if ( k >= i - x ) {
                ans += i - x;
            } else {
                ans += k;
            }
            x = i;
        }
    }
    if ( k >= n - x + 1 )
        ans += n - x + 1;
    else
        ans += k;

    fout << ans << "\n";
    fin.close();
    fout.close();
    return 0;
}