Pagini recente » Cod sursa (job #1004184) | Cod sursa (job #367900) | Cod sursa (job #1524438) | Istoria paginii runda/simulare-cartita-15a/clasament | Cod sursa (job #2938579)
#include <iostream>
#include <fstream>
#include <deque>
using namespace std;
ifstream f("secventa.in");
ofstream g("secventa.out");
deque<int> q;
int n, k, i, pi, ps, b = -30001, a[500005];
int main()
{
f >> n >> k;
for (i = 1; i <= k; i++)
{
f >> a[i];
while (!q.empty() && a[q.back()] > a[i])
q.pop_back();
q.push_back(i);
}
pi = 1, ps = k, b = a[q.front()];
for (i = k + 1; i <= n; i++)
{
f >> a[i];
while (!q.empty() && a[q.back()] > a[i])
{
q.pop_back();
}
if (q.front() == i - k)
q.pop_front();
q.push_back(i);
if (a[q.front()] > b)
b = a[q.front()], pi = i - k + 1, ps = i;
}
g << pi << " " << ps << " " << b;
}