Pagini recente » Cod sursa (job #3277910) | Cod sursa (job #3278337) | Cod sursa (job #2733789) | Cod sursa (job #2514229) | Cod sursa (job #3277618)
#include <bits/stdc++.h>
using namespace std;
ifstream fcin("secventa.in");
ofstream fcout("secventa.out");
const int N = 5e5 + 5;
int v[N], n, k;
deque<pair<int, int>> d;
int main()
{
fcin >> n >> k;
for (int i = 1; i <= n; i++)
fcin >> v[i];
int poz, bmax;
bmax = 0;
for (int i = 1; i <= n; i++)
{
while (!d.empty() && d.back().second > v[i])
d.pop_back();
d.push_back({i, v[i]});
if (d.front().first == i - k)
d.pop_front();
if (i >= k)
{
int baza = d.front().second;
if (baza > bmax)
{
bmax = baza;
poz = i;
}
}
}
fcout << poz - k + 1 << ' ' << poz << ' ' << bmax;
return 0;
}