Pagini recente » Cod sursa (job #1642968) | Cod sursa (job #1388658) | Cod sursa (job #1206269) | Cod sursa (job #918814) | Cod sursa (job #1388671)
#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;
}