Cod sursa(job #2124845)

Utilizator FunnyStockyMihnea Andreescu FunnyStocky Data 7 februarie 2018 17:39:43
Problema Secventa Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.66 kb
#include <cstdio>
using namespace std;
const int nmax=500000;
int n,k,v[nmax+5];
int deq[nmax+5],st=1,dr=0;
int best=-1e9,st_sol,dr_sol;
int main()
{
    freopen("secventa.in","r",stdin);
    freopen("secventa.out","w",stdout);
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&v[i]);
        if(st<=dr and i-deq[st]+1>k)
            st++;
        while(st<=dr and v[i]<=v[deq[dr]])
            dr--;
        deq[++dr]=i;
        if(i>=k and v[deq[st]]>best)
        {
            best=v[deq[st]];
            st_sol=i-k+1;
            dr_sol=i;
        }
    }
    printf("%d %d %d",st_sol,dr_sol,best);
    return 0;
}