Pagini recente » Cod sursa (job #1872092) | Cod sursa (job #173658) | Cod sursa (job #792380) | Cod sursa (job #2249871) | Cod sursa (job #1602595)
#include <iostream>
#include <list>
using namespace std;
struct item {
int val;
int pos;
};
int main (void) {
ios_base::sync_with_stdio(false);
freopen("secventa.in", "r", stdin);
freopen("secventa.out", "w", stdout);
int n, k;
cin >> n >> k;
int v[n];
for (int i = 0; i < n; ++i) {
cin >> v[i];
}
list<item> l;
item aux = {v[0], 0};
l.push_back(aux);
int max = v[0], startSol = 0;
for (int i = 1; i < n; ++i) {
if (l.front().pos < i - k + 1) l.pop_front();
while (!l.empty() && v[i] <= l.front().val) {
l.pop_front();
}
aux.val = v[i];
aux.pos = i;
l.push_back(aux);
if (l.front().val > max) {
max = l.front().val;
startSol = l.front().pos;
}
}
cout << startSol + 1 << " " << startSol + k << " " << max;
return 0;
}