Cod sursa(job #1131591)

Utilizator alexmarMarinescu Alexandru alexmar Data 28 februarie 2014 21:52:57
Problema Secventa Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.59 kb
#include <iostream>
#include<fstream>
using namespace std;
ifstream fin("secventa.in");
ofstream fout("secventa.out");

int d[500001],p,m=-30001,v[500001],k,n,FRONT,BACK;
int main()
{
    long i;
  fin>>n>>k;
  FRONT=1;BACK=0;
  for(i=1;i<=n;i++){fin>>v[i];
    while(FRONT<=BACK&&v[i]<=v[d[BACK]])BACK--;
    d[++BACK]=i;
    if(d[FRONT]==i-k)FRONT++;
    if(i>=k&&v[d[FRONT]]>=m){
            if(v[d[FRONT]]==m){if(v[i-k+1]<v[p-k+1]||(v[i-k+1]==v[p-k+1]&&v[i]<v[p]))p=i;}
            else p=i;m=v[d[FRONT]];
                }

  }
    fout<<p-k+1<<" "<<p<<" "<<m;

    return 0;
}