Pagini recente » Cod sursa (job #143181) | Cod sursa (job #2517706) | Cod sursa (job #219580) | Cod sursa (job #370762) | Cod sursa (job #1413849)
#include <iostream>
#include <fstream>
#include <deque>
using namespace std;
const int maxn = 500005;
const int oo = 0x3f3f3f3f;
int a[maxn], n, k, _st, _end;
int main() {
ifstream fin("secventa.in");
ofstream fout("secventa.out");
fin >> n >> k;
int _bestmax = -oo;
deque <int> dq;
for(int i = 1 ; i <= n ; ++ i) {
fin >> a[i];
while(!dq.empty() && a[dq.back()] >= a[i])
dq.pop_back();
dq.push_back(i);
if(dq.front() <= i - k)
dq.pop_front();
if(i >= k) {
if(_bestmax < a[dq.front()]) {
_bestmax = a[dq.front()];
_st = dq.front();
_end = i;
}
}
}
while(a[_st - 1] >= _bestmax) {
-- _st;
}
fout << _st << ' ' << _end << ' ' << _bestmax << "\n";
}