Cod sursa(job #1845004)

Utilizator kappapride123Kappa Pride kappapride123 Data 10 ianuarie 2017 19:13:32
Problema Secventa Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.98 kb
#include <fstream>
#include <algorithm>
#include <deque>

using namespace std;

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

int n, k;
deque < pair < int, int > > DQ;
int min_base, l, r;

int main()
{
    int x, i;
    fin >> n >> k;
    min_base = 30001;
    for (i = 1; i <= n; ++ i)
        {
         fin >> x;
         if (!DQ.empty() && DQ.front().second <= i - k)
            DQ.pop_front();
         while (!DQ.empty() && x <= DQ.back().first)
            DQ.pop_back();
         DQ.push_back(make_pair(x, i));
         if (!DQ.empty() && DQ.front().first < x || (DQ.front().first == x && DQ.front().second < l) || (DQ.front().first == x && DQ.front().second == l && DQ.back().second < r))
            {
             min_base = DQ.front().first;
             l = DQ.front().second;
             r = DQ.back().second;
            }
        }
    fin.close();
    fout << l << " " << r << " " << min_base << "\n";
    fout.close();
    return 0;
}