Cod sursa(job #2999631)

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

using namespace std;

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

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

int main()
{
    fin >> n >> k;
    for (int i = 1; i <= n; i++)
    {
        fin >> 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;
}