Cod sursa(job #1675263)

Utilizator serbanSlincu Serban serban Data 5 aprilie 2016 10:55:22
Problema Secventa Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.96 kb
#include <iostream>
#include <fstream>

#define pii pair<int, int>

using namespace std;

pii q[500005];
int l = 1;

int main()
{
    ifstream f("secventa.in");
    ofstream g("secventa.out");
    int n, k, x, st, dr, mx = -30005;
    f >> n >> k;
    for(int i = 1; i <= n; i ++) {
        f >> x;
        while(q[0].first >= l && q[q[0].first].first > x)
            q[0].first --;
        q[++ q[0].first] = {x, i};
        if(q[q[0].first].second - q[l].second >= k) {
            int aux = q[l].second;
            while(q[q[0].first].second - q[l].second >= k && q[l].second < q[l + 1].second)
                l ++;
            if(q[l].second != aux)
                aux = q[l - 1].second + 1;
            if(q[q[0].first].second - aux + 1 >= k && mx < q[l].first) {
                mx = q[l].first;
                st = aux;
                dr = i;
            }
        }
    }
    g << st << " " << dr << " " << mx << "\n";
    return 0;
}