Cod sursa(job #2888045)

Utilizator Ilie_MityIlie Dumitru Ilie_Mity Data 10 aprilie 2022 17:00:56
Problema Secventa Scor 60
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.73 kb
//Ilie Dmitru
#include<fstream>
typedef long long int ll;
const int NMAX=500005;
const ll MOD=194767;

std::ifstream f("secventa.in");
std::ofstream g("secventa.out");
int v[NMAX], dq[NMAX], start=0, end=-1;

int main()
{
    int N, K, i, maxB=-30005, pos;
    f>>N>>K;
    for(i=0;i<N;++i)
        f>>v[i];
    for(i=0;i<K;++i)
    {
        while(end>start && v[dq[end]]>=v[i])
            --end;
        dq[++end]=i;
    }
    pos=K-1;
    for(;i<N;++i)
    {
        while(end>start && v[dq[end]]>=v[i]) --end;
        dq[++end]=i;
        if(v[dq[start+=(dq[start]==i-K)]]>maxB)
            maxB=v[dq[start]], pos=i;
    }
    g<<pos-K+2<<' '<<pos+1<<' '<<maxB;
    f.close();
    g.close();
    return 0;
}