Pagini recente » Cod sursa (job #1799122) | Cod sursa (job #1245674) | Cod sursa (job #1171296) | Cod sursa (job #591552) | Cod sursa (job #1675263)
#include <iostream>
#include <fstream>
#define pii pair<int, int>
using namespace std;
pii q[500005];
int l = 1;
int main()
{
ifstream f("secventa.in");
ofstream g("secventa.out");
int n, k, x, st, dr, mx = -30005;
f >> n >> k;
for(int i = 1; i <= n; i ++) {
f >> x;
while(q[0].first >= l && q[q[0].first].first > x)
q[0].first --;
q[++ q[0].first] = {x, i};
if(q[q[0].first].second - q[l].second >= k) {
int aux = q[l].second;
while(q[q[0].first].second - q[l].second >= k && q[l].second < q[l + 1].second)
l ++;
if(q[l].second != aux)
aux = q[l - 1].second + 1;
if(q[q[0].first].second - aux + 1 >= k && mx < q[l].first) {
mx = q[l].first;
st = aux;
dr = i;
}
}
}
g << st << " " << dr << " " << mx << "\n";
return 0;
}