Pagini recente » Cod sursa (job #2808507) | Cod sursa (job #1343356) | Cod sursa (job #1953925) | Cod sursa (job #2033876) | Cod sursa (job #2124845)
#include <cstdio>
using namespace std;
const int nmax=500000;
int n,k,v[nmax+5];
int deq[nmax+5],st=1,dr=0;
int best=-1e9,st_sol,dr_sol;
int main()
{
freopen("secventa.in","r",stdin);
freopen("secventa.out","w",stdout);
scanf("%d%d",&n,&k);
for(int i=1;i<=n;i++)
{
scanf("%d",&v[i]);
if(st<=dr and i-deq[st]+1>k)
st++;
while(st<=dr and v[i]<=v[deq[dr]])
dr--;
deq[++dr]=i;
if(i>=k and v[deq[st]]>best)
{
best=v[deq[st]];
st_sol=i-k+1;
dr_sol=i;
}
}
printf("%d %d %d",st_sol,dr_sol,best);
return 0;
}