Pagini recente » Cod sursa (job #2256167) | Cod sursa (job #2921899) | Cod sursa (job #2753715) | Cod sursa (job #1009421) | Cod sursa (job #2309068)
#include <iostream>
#include <fstream>
using namespace std;
int n,k;
pair<int,int> q[5000001];
int x[5000001];
int first=0,last=-1;
int main()
{
ifstream f("secventa.in");
f>>n>>k;
for(int i=1;i<=n;i++)
f>>x[i];
f.close();
int a;
for(int i=1;i<=k;i++)
{
while(last!=first-1 && q[last].first>x[i])
last--;
q[++last].first=x[i];
q[++last].second=i;
}
int poz=q[first].second,dr=k,st;
for(int i=k+1;i<=n;i++)
{
if(q[first].second<=i-k)
first++;
while(last!=first-1 && q[last].first>x[i])
last--;
q[++last].first=x[i];
q[++last].second=i;
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++;
ofstream g("secventa.out");
g<<st<<' '<<dr<<' '<<x[poz];
g.close();
return 0;
}