Cod sursa(job #2124840)

Utilizator FunnyStockyMihnea Andreescu FunnyStocky Data 7 februarie 2018 17:34:59
Problema Secventa Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.64 kb
#include <fstream>
#include <vector>
using namespace std;
ifstream cin("perechi.in");
ofstream cout("perechi.out");
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()
{
    cin>>n>>k;
    for(int i=1;i<=n;i++)
    {
        cin>>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;
        }
    }
    cout<<st_sol<<" "<<dr_sol<<" "<<best;
    return 0;
}