Pagini recente » Cod sursa (job #3322419) | Cod sursa (job #1630927) | Cod sursa (job #2081315) | Cod sursa (job #3316431) | Cod sursa (job #3314509)
#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.empty() && i-q.front()>=k) q.pop_front();
while (!q.empty() && v[q.back()]>=v[i]) q.pop_back();
q.push_back(i);
if (v[q.front()]>v[pmax]) {lmax=i-k+1; rmax=i; pmax=q.front();}
}
fout<<lmax<<" "<<rmax<<" "<<v[pmax];
return 0;
}