Pagini recente » Cod sursa (job #1524087) | Cod sursa (job #2635948) | Cod sursa (job #1882999) | Cod sursa (job #1959866) | Cod sursa (job #1963060)
#include <iostream>
#include <fstream>
#include <deque>
using namespace std;
int n, i, j, mx=-30005, a, b, x, k;
deque <int> dq, pq;
int main()
{
ifstream fin("secventa.in");
ofstream fout("secventa.out");
fin >> n >> k;
for (i = 1; i <= n; i++)
{
fin >> x;
if (!dq.empty() && pq.front() <= i-k)
{
pq.pop_front();
dq.pop_front();
}
while (!dq.empty() && dq.back() >= x)
{
pq.pop_back();
dq.pop_back();
}
pq.push_back(i);
dq.push_back(x);
if (i >= k)
{
a = pq.front(); b = a+k-1;
mx = dq.front();
}
//for (j = 0; j < dq.size(); j++) cout << dq[j] << " ";
//cout << "\n";
}
fout << a << " " << b << " " << mx << "\n";
}