Cod sursa(job #1963064)

Utilizator shantih1Alex S Hill shantih1 Data 12 aprilie 2017 11:40:51
Problema Secventa Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.79 kb
#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 && dq.front() > mx)
        {
            a = pq.front();  b = a+k-1;
            mx = dq.front();
        }
    }

    fout << a << " " << b << " " << mx << "\n";
}