Cod sursa(job #237405)

Utilizator eugen.nodeaEugen Nodea eugen.nodea Data 29 decembrie 2008 18:17:05
Problema Secventa Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.51 kb
# include <stdio.h>
# define nmax 500001
long N,K,C[nmax];
int a[nmax];

int main(){
  long i,st,dr,max=0,x,y;

  freopen("secventa.in", "r", stdin);
  freopen("secventa.out", "w", stdout);
  scanf("%ld %ld",&N,&K);
  for (i=1;i<=N;i++)
    scanf("%ld ",&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("%ld %ld %ld",x,y,max);
  return 0;
}