Cod sursa(job #2999622)

Utilizator OneShotStefBurlacenco Bayer Stefan OneShotStef Data 11 martie 2023 11:12:59
Problema Secventa Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.66 kb
#include <iostream>
#include <fstream>

using namespace std;

ifstream fin("secventa.in");
ofstream fout("secventa.out");

int n, a[500001], q[500001], k, mx = 0, pi = 0, pj = 0;
int uq = -1, pq = 0;

int main()
{
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    for (int i = 1; i <= n; i++)
    {
        while (pq <= uq && a[i] <= a[q[uq]])
        {
            uq--;
        }
        q[++uq] = i;
        if (q[pq] <= i - k)pq++;
        if (a[q[pq]] > mx)
        {
            mx = a[q[pq]];
            pi = q[pq];
            pj = q[uq];
        }
    }
    fout << pi<<" " << pj<<" " << mx;
}