Cod sursa(job #2502239)

Utilizator hurjui12AlexandruHurjui Alexandru-Mihai hurjui12Alexandru Data 30 noiembrie 2019 15:32:46
Problema Secventa Scor 80
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.83 kb
#include <fstream>
#include <queue>
using namespace std;

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

int main()
{
    int n, k, i, x;
    int bmax, ibmax;
    deque <pair <int, int>> d;
    fin >> n >> k;
    for (i = 1; i<=k; i++)
    {
        fin >> x;
        while (d.empty() == 0 && d.front().first > x)
            d.pop_front();
        d.push_front({x, i});
    }
    ibmax = k;
    bmax = d.back().first;
    for (i = k+1; i<=n; i++)
    {
        fin >> x;
        while (d.empty() == 0 && d.front().first > x)
            d.pop_front();
        d.push_front({x, i});
        if (i - d.back().second == k)
            d.pop_back();
        if (d.back().first > bmax)
        {
            bmax = d.back().first;
            ibmax = i;
        }
    }
    fout << ibmax - k + 1 << ' ' << ibmax << ' ' << bmax;
    return 0;
}