Pagini recente » Cod sursa (job #645150) | Cod sursa (job #1097511) | Cod sursa (job #697266) | Cod sursa (job #2731607) | Cod sursa (job #23293)
Cod sursa(job #23293)
#include<fstream.h>
#include<stdio.h>
#define infi 32000
int long pos[500000],ind,sf,inc,d,max,i,n,k,x,j;
int st[500000];
int main()
{char sir[500000];
freopen("secventa.in","r",stdin);
scanf("%ld%ld",&n,&k);
scanf("%d",&st[1]);
st[0]=-infi;
inc=sf=1;
pos[sf]=1;
//fgets(sir,500000,stdin);
//ind=0;
for(i=2;i<=k;i++)
{scanf("%d",&x);
//for(x=0,++ind;sir[ind]>='0'&&sir[ind]<='9';ind++)
// x=x*10+sir[ind]-'0';
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);
//for(x=0,++ind;sir[ind]>='0'&&sir[ind]<='9';ind++)
// x=x*10+sir[ind]-'0';
if(pos[inc]==i-k)
st[inc++]=-infi;
// inc++;
for(sf;st[sf]>=x;sf--);
//while(sf>=inc&&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;
}