Cod sursa(job #277564)

Utilizator andumMorie Daniel Alexandru andum Data 11 martie 2009 19:49:31
Problema Secventa Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.67 kb
#include <stdio.h>

int n,k,p,u,a[500001],x,y,max=-20000000,d[500001],i;

int main()
{
    freopen("secventa.in","r",stdin);
    freopen("secventa.out","w",stdout);
    scanf("%d %d", &n, &k);
    p=1; u=0;
    for (i=1;i<=n;++i)
        {
         scanf("%d", &a[i]);
         while (p<=u && a[i]<=a[d[u]])
               u--;
         d[++u]=i;
         if (d[p]==i-k) ++p;
         if (i>=k) 
          if (a[d[p]]>max) 
                           {
                            max=a[d[p]];
                            x=i-k+1;
                            y=i;
                           } 
        }
    printf("%d %d %d", x, y, max);
    return 0;
}