Pagini recente » Cod sursa (job #2718970) | Cod sursa (job #2940424) | Cod sursa (job #1543642) | Cod sursa (job #1380858) | Cod sursa (job #1131591)
#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;
}