Cod sursa(job #2813002)

Utilizator andreiiorgulescuandrei iorgulescu andreiiorgulescu Data 5 decembrie 2021 16:54:40
Problema Secventa Scor 80
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.75 kb
#include <bits/stdc++.h>

using namespace std;

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

int n,k,maxim = -1e9,st,dr,x;
deque<pair<int,int>>d;

int main()
{
    ios_base::sync_with_stdio(false);
    in.tie(NULL);
    out.tie(NULL);
    in >> n >> k;
    for (int i = 1; i <= n; i++)
    {
        in >> x;
        while (d.size() and d.front().second < i - k + 1)
            d.pop_front();
        while (d.size() and d.back().first >= x)
            d.pop_back();
        d.push_back(make_pair(x,i));
        if (i >= k and d.front().first > maxim)
        {
            maxim = d.front().first;
            st = i - k + 1;
            dr = i;
        }
    }
    out << st << " " << dr << " " << maxim;
    return 0;
}