Cod sursa(job #2999628)

Utilizator AlexMoto2006Motoasca Alexandru-Lucian AlexMoto2006 Data 11 martie 2023 11:15:07
Problema Secventa Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.81 kb
#include <fstream>
#include <deque>
using namespace std;
deque <pair<int,int>> dq;
ifstream cin("secventa.in");
ofstream cout("secventa.out");
int main()
{
    int n, k;
    int max = -1;
    cin >> n;
    cin >> k;
    int x;
    int r = 0;
    for (int i = 1; i <= n; i++)
    {
        cin >> x;
        while (!dq.empty() && dq.back().first >= x)
        {
            dq.pop_back();
        }
        dq.push_back(make_pair(x, i));
        while (!dq.empty() && dq.front().second <= i - k)
        {
            dq.pop_front();
        }
        if (i >= k)
        {
            int y = dq.front().first;
            if (y > max)
            {
                max = y;
                r = i;
            }
        }
    }
    cout << r - k+1<<" " << r << " " << max;
    return 0;
}