Pagini recente » Cod sursa (job #2835316) | Cod sursa (job #826632) | Cod sursa (job #916029) | Cod sursa (job #900974) | Cod sursa (job #3314511)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("secventa.in");
ofstream fout("secventa.out");
int n,k,v[500005],i,pmax,lmax,rmax;
deque <int> q;
int main()
{
fin>>n>>k;
for (i=1; i<=n; i++) fin>>v[i];
pmax=0;
lmax=1;
rmax=k;
for (i=1; i<=n; i++)
{
if (q.front() <= i - k) q.pop_front();
while (!q.empty() && v[q.back()]>=v[i]) q.pop_back();
q.push_back(i);
if (i>=k) if (v[q.front()]>v[pmax])
{
lmax=i-k+1;
rmax=i;
pmax=q.front();
}
}
fout<<lmax<<" "<<rmax<<" "<<v[pmax];
return 0;
}