Cod sursa(job #2491519)

Utilizator Vlad.Vlad Cristian Vlad. Data 12 noiembrie 2019 18:22:23
Problema Secventa Scor 60
Compilator cpp-32 Status done
Runda Arhiva de probleme Marime 0.75 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;

}