Pagini recente » Cod sursa (job #853700) | Cod sursa (job #3168350) | Cod sursa (job #2742523) | Cod sursa (job #1312317) | Cod sursa (job #2309065)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("secventa.in");
ofstream g("secventa.out");
int n,k;
pair<int,int> q[5000001];
int x[5000001];
int first=0,last=-1;
int main()
{
f>>n>>k;
int a;
for(int i=1;i<=k;i++)
{
f>>x[i];
while(last!=first-1 && q[last].first>x[i])
last--;
q[++last]=make_pair(x[i],i);
}
int poz=q[first].second,dr=k,st;
for(int i=k+1;i<=n;i++)
{
f>>x[i];
while(last!=first-1 && q[last].first>x[i])
last--;
q[++last]=make_pair(x[i],i);
if(q[first].second<=i-k)
first++;
if(x[poz]<q[first].first)
poz=q[first].second,dr=q[last].second;
}
st=dr-k+1;
x[0]=-30001;
while(x[poz]<=x[--st]);
st++;
g<<st<<' '<<dr<<' '<<x[poz];
f.close();
g.close();
return 0;
}