Cod sursa(job #23283)

Utilizator pocaituDavid si Goliat pocaitu Data 28 februarie 2007 16:13:51
Problema Secventa Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.64 kb
#include<fstream.h>
#include<stdio.h>
#define infi 1000000
int long pos[500000],sf,inc,d,max,i,n,k,x,j;
int st[500000];
int main()
{freopen("secventa.in","r",stdin);
 f>>n>>k;
 f>>st[1];
 st[0]=-infi;
 inc=sf=1;
 pos[sf]=1;
 for(i=2;i<=k;i++)
   {scanf("%d",&x);
   for(j=sf;st[j]>=x;j--);
	st[j+1]=x;
	sf=j+1;
   pos[sf]=i;
   }
 max=st[1];
 for(i=k+1;i<=n;i++)
  {scanf("%d",&x);
   if(pos[inc]==i-k)
	 st[inc++]=-infi;
   for(sf;st[sf]>=x;sf--);
   st[++sf]=x;
   pos[sf]=i;
   if(st[inc]>max)
	 {max=st[inc];
	  d=i;
	  }
   }

 ofstream g("secventa.out");
 g<<d-k+1<<" "<<d<<" "<<max;
 g.close();
 return 0;
 }