Cod sursa(job #344313)

Utilizator xtremespeedzeal xtreme Data 29 august 2009 17:29:28
Problema Secventa Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.78 kb
#include <fstream.h>
#include <iostream.h>
#define nmax 500001

int v[nmax],poz[nmax],min=-30001;
int  n,k,i,sfpoz;

void citeste()
     {ifstream in("secventa.in");int h;
      in>>n>>k;
	  for(h=1;h<=n;h++)    in>>v[h];
	  in.close();
     }
void scrie()
     {ofstream out("secventa.out");
      out<<sfpoz-k+1<<" "<<sfpoz<<" "<<min<<"\n";
      out.close();
      }
void rezolva()
     {int first=1,last=0;
      for (i=1;i<=n;i++)
	       {while(first<=last && v[i]<=v[poz[last]])  --last;
		    poz[++last]=i;
		    if(i-poz[first]==k)   first++;
            if(i>=k && v[poz[first]]>min)
		           {min=v[poz[first]];
		            sfpoz=i;
		           }
	       }
     }			
int main()
    {citeste();
     rezolva();
     scrie();
     return 0;
    }