Cod sursa(job #1979843)

Utilizator stefdascalescuStefan Dascalescu stefdascalescu Data 11 mai 2017 15:32:19
Problema Zombie Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.54 kb
#include<bits/stdc++.h>
using namespace std;
ifstream f("zombie.in");
ofstream g("zombie.out");
int d,n,k,x;
long long sol;
deque<int>v;
int main()
{
    f>>d>>n>>k;
    f>>x;
    v.push_back(x);
    int sz=1;
    for(int i=2;i<=n;++i)
    {
        f>>x;
        if(x-v[0]<d)
            v.push_back(x),++sz;
        else{
            sol=sol+min(k,sz);
            while(v.size())
                v.pop_front();
            sz=1;
            v.push_back(x);
        }
    }
    sol=sol+min(k,sz);
    g<<sol;
    return 0;
}