Pagini recente » Profil tcostin | Winter Challenge 2008 | cntnk | Rating Popescu Mihai Daniel (MikeDP) | Cod sursa (job #1002279)
#include<fstream>
#include<cstdio>
#include<deque>
#define N 500010
#define D 700000
using namespace std;
ofstream g("secventa.out");
int n,k,i,p,u,pz,maxi,a[N];
int poz=D+3; char buf[D];
deque<int> d;
inline int ianr()
{
unsigned int nr=0;
while((buf[poz]<'0'||buf[poz]>'9')&&buf[poz]!='-')
if(++poz>=D)
fread(buf,D,1,stdin),poz=0;
int semn=1;
if(buf[poz]=='-')
++poz,semn=-1;
while('0'<=buf[poz]&&buf[poz]<='9')
{
nr=nr*10+buf[poz]-'0';
if(++poz>=D)
fread(buf,D,1,stdin),poz=0;
}
return nr*semn;
}
int main()
{
freopen("secventa.in","r",stdin);
n=ianr();
k=ianr();
for(i=1;i<=n;++i)
a[i]=ianr();
u=0;
maxi=-999999999;
u=0;
for(i=1;i<=n;++i)
{
while(!d.empty()&&a[d.back()]>a[i])
d.pop_back();
d.push_back(i);
if(d.front()==i-k)
d.pop_front();
if(i>=k&&a[d.front()]>maxi)
{
maxi=a[d.front()];
u=i;
}
}
g<<u-k+1<<" "<<u<<" "<<maxi<<'\n';
return 0;
return 0;
}