Pagini recente » Cod sursa (job #2748295) | Cod sursa (job #2694854) | Cod sursa (job #139122) | Cod sursa (job #2636138) | Cod sursa (job #2117357)
#include <bits/stdc++.h>
#define NMAX 500001
using namespace std;
ifstream fin("secventa.in");
ofstream fout("secventa.out");
int main()
{
deque<int> q;
int a[NMAX];
int bazamax = -30000;
int n,k,i,poz;
fin >> n >> k;
for ( i = 1; i <= n; i++ )
{
fin >> a[i];
while ((q.size() > 0) && (a[q.back()] > a[i]))
{
q.pop_back();
}
q.push_back(i);
if (i - q.front() >= k)
{
q.pop_front();
}
if ( a[q.front()] > bazamax)
{
bazamax = a[q.front()];
poz = i ;
}
}
fout << poz-k+1 << " " << poz << " " << bazamax ;
return 0;
}