Cod sursa(job #2789669)

Utilizator AlexNicuNicu Alexandru AlexNicu Data 27 octombrie 2021 19:53:26
Problema Zombie Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <fstream>
#include <stack>

using namespace std;

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

stack<int> zombie;

int main() {
    int d, n, k, i, last, x, nr_stiva;
    long long ans;
    cin >> d >> n >> k;
    cin >> last;
    zombie.push(last);
    ans = 0;
    for ( i = 0; i < n; i++ ) {
        cin >> x;
        if ( x - last > d ) {
          nr_stiva = zombie.size();
          ans = ans + min ( nr_stiva, k );
          while ( !zombie.empty() ) {
            zombie.pop();
          }
          last = x;
        }
        zombie.push(x);
    }
    nr_stiva = zombie.size();
    ans += min ( nr_stiva, k );
    cout << ans << "\n";
    return 0;
}