Pagini recente » Cod sursa (job #2568379) | Cod sursa (job #3286811) | Utilizatori inregistrati la Stelele Informaticii 2010, gimnaziu si clasa a IX-a, Ziua 2 | Cod sursa (job #2129064) | Cod sursa (job #3283908)
#include <bits/stdc++.h>
using namespace std;
ifstream in("secventa.in");
ofstream out("secventa.out");
const int NMAX = 5e5 + 3;
int n, k;
int v[NMAX];
int main() {
in >> n >> k;
deque<int> q;
int hmax = INT_MIN, x = 0, y = 0;
for(int i = 1; i <= n; i++) {
in >> v[i];
while(!q.empty() && v[i] < v[q.back()]) {
q.pop_back();
}
q.push_back(i);
while(!q.empty() && i - k >= q.front()) {
q.pop_front();
}
if(i >= k && hmax < v[q.front()]) {
hmax = v[q.front()];
x = i - k + 1;
y = i;
}
}
out << x << ' ' << y << ' ' << hmax;
return 0;
}