Cod sursa(job #237531)

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

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

  freopen("secventa.in", "r", stdin);
  freopen("secventa.out", "w", stdout);
  scanf("%ld %ld",&N,&K);
  p=1;
  for (i=1;i<=N;i++){
    scanf("%d ",&a[i]);
    if (a[p]>a[i]&& i<K) p=i;
  }
  st=1; dr=0;
  for (i=p;i<=N-K/2+1;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;
}