Cod sursa(job #2938144)

Utilizator Chiri_Robert Chiributa Chiri_ Data 11 noiembrie 2022 18:25:39
Problema Secventa Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.68 kb
#include <bits/stdc++.h>

using namespace std;

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

int n, k, a[500000];
deque<int> q;
int st, sf, b;

int main()
{
    fin >> n >> k;
    for (int i = 0; i < n; i++) {
        fin >> a[i];

        while (!q.empty() && a[i] < a[q.back()]) {
            q.pop_back();
        }
        q.push_back(i);
        if (q.front() <= i-k) {
            q.pop_front();
        }
        if (i >= k-1) {
            if (a[q.front()] > b) {
                b = a[q.front()];
                st = i-k+2;
                sf = i+1;
            }
        }
    }
    fout << st << " " << sf << " " << b;
    return 0;
}