Cod sursa(job #1388671)

Utilizator alexmarMarinescu Alexandru alexmar Data 15 martie 2015 17:15:05
Problema Secventa Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.55 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=1,b=0,m=-30001;
    fin>>n>>k;
    for(int i=1;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]]>m){
                m=a[d[f]];
                ind=i;
            }
    }
    fout<<ind-k+1<<" "<<ind<<" "<<m;
    return 0;
}