Cod sursa(job #3122593)

Utilizator unomMirel Costel unom Data 19 aprilie 2023 18:21:29
Problema Secventa Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.73 kb
#include <fstream>
#include <queue>

using namespace std;

ifstream in("secventa.in");
ofstream out("secventa.out");
int n, k;
int ans = -99999999;
int st, dr;
deque <pair<int, int>> q;

int main()
{
    in>>n>>k;

    int x;

    for(int i = 1; i<=n; i++)
    {
        in>>x;

        while(!q.empty() && x <= q.back().first)
        {
            q.pop_back();
        }

        q.push_back({x, i});

        if(i >= k && q.front().first > ans)
        {
            ans = q.front().first;
            st = i - k + 1;
            dr = i;
        }

        if(q.front().second == i - k + 1)
        {
            q.pop_front();
        }
    }

    out<<st<<" "<<dr<<" "<<ans;

    return 0;
}