Cod sursa(job #2117357)

Utilizator liviu2000Dragomirescu Liviu liviu2000 Data 28 ianuarie 2018 20:11:15
Problema Secventa Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.72 kb
#include <bits/stdc++.h>
#define NMAX 500001

using namespace std;

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

int main()
{
    deque<int> q;
    int a[NMAX];
    int bazamax = -30000;
    int n,k,i,poz;
    fin >> n >> k;

    for ( i = 1; i <= n; i++ )
    {
        fin >> a[i];
        while ((q.size() > 0) && (a[q.back()] > a[i]))
        {
            q.pop_back();
        }
        q.push_back(i);
        if (i - q.front() >= k)
        {
            q.pop_front();
        }
        if ( a[q.front()] > bazamax)
        {
            bazamax = a[q.front()];
            poz = i ;
        }
    }

    fout << poz-k+1 << " " << poz << " " << bazamax ;
    return 0;
}