Cod sursa(job #2046170)

Utilizator sabinantonSabin Anton sabinanton Data 23 octombrie 2017 15:24:21
Problema Secventa Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.55 kb
#include <bits/stdc++.h>

using namespace std;
ifstream fin("secventa.in");
ofstream fout("secventa.out");
long long n,m,i,j,v[1000001],stiva[1000001],k,d[10000001],st,dr,mx=-300000000,a,b;
int main()
{
    fin>>n>>k;
    st=0;
    dr=-1;
    for(i=0;i<n;i++)
    {
        fin>>v[i];
      if(st<=dr&&d[st]==i-k)
        st++;
       while(st<=dr&&v[i]<=v[d[dr]])
      {
          dr--;
      }
      d[++dr]=i;
      if(v[d[st]]>mx)
      {
          mx=v[d[st]];
          a=i-k+2;
          b=i+1;
      }
    }
    fout<<a<<" "<<b<<" "<<mx;
    return 0;
}