Cod sursa(job #1388658)

Utilizator alexmarMarinescu Alexandru alexmar Data 15 martie 2015 17:10:06
Problema Secventa Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.57 kb
#include<iostream>
#include<fstream>

using namespace std;
int n,k,a[500050],d[500050],ind;


int main()
{
    ifstream fin("secventa.in");
    ofstream fout("secventa.out");
     int f=0,b=-1,ma=-30001;
    fin>>n>>k;
    for(int i=0;i<=n;++i)
        fin>>a[i];

    for(int i=1;i<=n;++i)
    {
        while((f<=b)&&(a[i]<=a[d[b]]))--b;
        ++b;
        d[b]=i;
        if(d[f]==i-k)++f;
        if(i>=k&&a[d[f]]>ma){
                ma=a[d[f]];
                ind=i;
            }
    }
    fout<<ind-k+2<<" "<<ind+1<<" "<<ma;
    return 0;
}