Pagini recente » Cod sursa (job #2667383) | Cod sursa (job #3173466) | Cod sursa (job #3125713) | Cod sursa (job #1918517) | Cod sursa (job #23305)
Cod sursa(job #23305)
#include<fstream.h>
#include<stdio.h>
#define infi 32001
int long pos[5003],ind,sf,inc,d,max,i,n,k,j;
int st[5003],x;
char t;
int main()
{//char sir[5000];
freopen("secventa.in","r",stdin);
scanf("%ld%ld",&n,&k);
scanf("%ld",&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(;st[sf]>=x;sf--);
st[++sf]=x;
pos[sf]=i;
}
max=st[1];
d=k;
for(i=k+1;i<=n;i++)
{scanf("%d",&x);
//for(ind=0;t[ind]<='9'&&t[ind]>='0';ind--)
//x=x*10+t[ind]-'0';
//for(x=0,++ind;sir[ind]>='0'&&sir[ind]<='9';ind++)
// x=x*10+sir[ind]-'0';
// inc++;
if(pos[inc]<=i-k)
st[inc++]=-infi;
for(;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;
}