Cod sursa(job #2046190)

Utilizator StepHoria Stefan Step Data 23 octombrie 2017 15:39:56
Problema Secventa Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.67 kb
#include <iostream>
#include <fstream>

using namespace std;

ifstream f("secventa.in");
ofstream g("secventa.out");

const int N=500001;
int v[N],d[N];

int main()
{
    int n,k,i,maxim=-30000000,st,dr,stmax,drmax;
    f>>n>>k;
    st=0;
    dr=-1;
    for (i=1; i<=n; i++)
    {
        f>>v[i];
        if (st<=dr&&d[st]==i-k)
        {
            ++st;
        }
        while (st<=dr&&v[i]<=v[d[dr]])
            dr--;
        d[++dr]=i;
        if (i>=k-1)
        {
            if (v[d[st]]>maxim)
            {
                maxim=v[d[st]];
                stmax=i-k+1;
                drmax=i;
            }
        }
    }
    g<<stmax<<" "<<drmax<<" "<<maxim;
    return 0;
}