Cod sursa(job #3283908)

Utilizator tryharderulbrebenel mihnea stefan tryharderul Data 10 martie 2025 17:55:26
Problema Secventa Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <bits/stdc++.h>

using namespace std;

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

const int NMAX = 5e5 + 3;

int n, k;
int v[NMAX];

int main() {

    in >> n >> k;

    deque<int> q;
    int hmax = INT_MIN, x = 0, y = 0;
    for(int i = 1; i <= n; i++) {
        in >> v[i];
        while(!q.empty() && v[i] < v[q.back()]) {
            q.pop_back();
        }
        q.push_back(i);
        while(!q.empty() && i - k >= q.front()) {
            q.pop_front();
        }
        if(i >= k && hmax < v[q.front()]) {
            hmax = v[q.front()];
            x = i - k + 1;
            y = i;
        }
    }

    out << x << ' ' << y << ' ' << hmax;

    return 0;
}