Cod sursa(job #963237)

Utilizator robertstrecheStreche Robert robertstreche Data 16 iunie 2013 21:16:44
Problema Secventa Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.51 kb
#include <fstream>

using namespace std;
ifstream f("secventa.in");
ofstream g("secventa.out");
int a[5100000],n,ok,q,i,p=1,k,u,d[5100000];
long long e=-100000000;
int main()
{
    f>>n>>k;
    for (i=1;i<=n;i++)
     {f>>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=d[p];
         }

     }
     g<<q-k+1<<" "<<q<<" "<<e;


    f.close();
    g.close();
}