Cod sursa(job #1991128)

Utilizator Y0da1NUME JMECHER Y0da1 Data 15 iunie 2017 12:31:29
Problema Secventa Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.9 kb
#include <iostream>
#include <fstream>
#include <deque>
#include <algorithm>
using namespace std;

deque <pair <int, int> > D;

int main()
{
    int i;
    int n, k, maxim =-2e9, b, e;
    long long s = 0;
    pair <int, int> x;
    ifstream in ("secventa.in");
    ofstream out ("secventa.out");

    in>>n>>k;

    for(i=0;i<n;++i)
    {
        x.first = i;
        in>>x.second;

        if(!D.empty() && D.front().first <= i-k)
            D.pop_front();

        while (!D.empty() && D.back().second >x.second)
        {
            D.pop_back();
        }

        D.push_back(x);

        if(i>=k-1)
            {
                if(D.front().second > maxim)
                {
                    maxim = D.front().second;
                    b=D.front().first;
                    e=b+k;
                }
            }

    }
    out<<b+1<<" "<<e<<" "<<maxim;

}