Pagini recente » Cod sursa (job #2316925) | Cod sursa (job #1865395) | Cod sursa (job #990395) | Cod sursa (job #765803) | Cod sursa (job #237402)
Cod sursa(job #237402)
# include <stdio.h>
# define nmax 500001
int N,K,a[nmax],C[nmax];
int main(){
int i,st,dr,max=0,x,y;
freopen("secventa.in", "r", stdin);
freopen("secventa.out", "w", stdout);
scanf("%d %d",&N,&K);
for (i=1;i<=N;i++)
scanf("%d ",&a[i]);
st=1; dr=0;
for (i=1;i<=N;i++){
while (st<=dr && a[i]<=a[C[dr]]) dr--;
C[++dr]=i;
if (C[st]==i-K) st++;
if (i>=K && a[C[st]]>max){
max=a[C[st]];
x=i-K+1; y=i;
};
}
printf("%d %d %d",x,y,max);
return 0;
}