Pagini recente » Cod sursa (job #2959078) | Cod sursa (job #2336990) | Cod sursa (job #255732) | Cod sursa (job #426646) | Cod sursa (job #2309052)
#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;
for(int i=k;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;
}
int st=poz-1;
while(x[st]>=x[poz])
st--;
st++;
int dr=poz;
if(dr-st+1<=k)
dr+=(k-dr+st-1);
g<<st<<' '<<dr<<' '<<x[poz];
f.close();
g.close();
return 0;
}