Cod sursa(job #2462964)

Utilizator Vlad.Vlad Cristian Vlad. Data 28 septembrie 2019 10:06:37
Problema Secventa Scor 80
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.79 kb
#include <fstream>
#include <deque>

using namespace std;

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

int n, k, currentNr;
deque<pair<int, int>> deq;
int bazaMaxi;
int pSf;

int main()
{
    fin >> n >> k;
    bazaMaxi = -2147483648;
    for (int i = 0; i < n; ++i) {
        fin >> currentNr;
        while (!deq.empty() && currentNr <= deq.back().first) {
            deq.pop_back();
        }
        deq.push_back(make_pair(currentNr, i));
        if (i - deq.front().second == k) {
            deq.pop_front();
        }
        if (i >= k - 1 && deq.front().first > bazaMaxi)
        {
            bazaMaxi = deq.front().first;
            pSf = i;
        }
    }
    fout << pSf - k + 2 << " " << pSf + 1 << " " << bazaMaxi << "\n";
    return 0;
}