Cod sursa(job #2999635)

Utilizator doruliqueDoru MODRISAN dorulique Data 11 martie 2023 11:17:43
Problema Secventa Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.69 kb
#include <bits/stdc++.h>
#define MAXSZ 500000

using namespace std;

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

int n, k, lo = -1, hi = -1, maxi = INT_MIN, arr[MAXSZ+1];
deque<int> dq;

int main() {
    fin >> n >> k;
    for (int i = 1; i <= n; i++) {
        fin >> arr[i];
        while (!dq.empty() && arr[dq.back()] >= arr[i])
            dq.pop_back();
        dq.push_back(i);
        if (dq.front() == i - k)
            dq.pop_front();
        if (i >= k  && arr[dq.front()] > maxi) {
            lo = i - k + 1;
            hi = i;
            maxi = arr[dq.front()];
        }
    }

    fout << lo << ' ' << hi << ' ' << maxi << '\n';
    return 0;
}