Cod sursa(job #963244)

Utilizator robertstrecheStreche Robert robertstreche Data 16 iunie 2013 21:27:40
Problema Secventa Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.55 kb
#include <cstdio>
#include <fstream>
using namespace std;

int a[5100000],n,ok,q,i,p=1,k,u,d[5100000];
long long e=-100000000;
int main()
{
    freopen("secventa.in","r",stdin);
    freopen("secventa.out","w",stdout);
    scanf("%d %d\n",&n,&k);
    for (i=1;i<=n;i++)
     {scanf("%d ",&a[i]);
         while (p<=u && a[i]<a[d[u]])u--;
         d[++u]=i;
        while (p<=u && d[p]<=i-k)p++;
         if (i>=k && a[d[p]]>e)
         {
             e=a[d[p]];
             q=i;
         }

     }
      printf("%d %d %d",q-k+1,q,e);

}