Cod sursa(job #2888013)

Utilizator Ilie_MityIlie Dumitru Ilie_Mity Data 10 aprilie 2022 16:26:45
Problema Secventa Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.73 kb
//Ilie Dumitru
#include<cstdio>
typedef long long int ll;
const int NMAX=500005;
const ll MOD=194767;

FILE* f=fopen("secventa.in", "r"), *g=fopen("secventa.out", "w");

int baza[NMAX], index[NMAX], start=0, end=0;

int main()
{
    int N, K, i, x, maxB=-30005, pos;
    fscanf(f, "%d%d", &N, &K);
    for(i=0;i<N;++i)
    {
        fscanf(f, "%d", &x);
        while(end>start && baza[end]>=x)
            --end;
        baza[end]=x;
        index[end]=i;
        ++end;
        while(start<end && index[start]<=i-K)
            ++start;
        if(baza[start]>maxB && i>=K)
            maxB=baza[start], pos=i;
    }
    fprintf(g, "%d %d %d", pos-K+2, pos+1, maxB);
    fclose(f);
    fclose(g);
    return 0;
}