Cod sursa(job #1534406)

Utilizator mariusadamMarius Adam mariusadam Data 23 noiembrie 2015 18:29:39
Problema Secventa Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.77 kb
#include <deque>
#include <fstream>
#define pb push_back
#define mp make_pair
using namespace std;

struct elem{
    int val, ind;
} DE[500001];
int n, k, x, st = 0, sf = -1, sz = 0, poz = 0, bmax = -(1 << 30);

int main() {
    ifstream r("secventa.in");
    ofstream w("secventa.out");
    r >> n >> k;
    for (int i = 1; i <= n; i++) {
        r >> x;
        while (sf >= st and x <= DE[sf].val)
            sf = sf - 1;
        sf++;
        DE[sf].val = x;
        DE[sf].ind = i;
        if (i - DE[st].ind + 1 > k)
            st++;
        if (i >= k && DE[st].val > bmax) {
            bmax = DE[st].val;
            poz = i;
        }
    }
    w << poz - k + 1 << " " << poz << " " << bmax;
    r.close();
    w.close();
    return 0;
}