Cod sursa(job #1976125)

Utilizator NicolaalexandraNicola Alexandra Mihaela Nicolaalexandra Data 2 mai 2017 20:12:47
Problema Secventa Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.68 kb
#include <cstdio>
using namespace std;
int n,i,v[500001],k,p,j,u,maxim,x,p1,p2,k2,d[500001];
FILE *fin = fopen ("secventa.in", "r");
FILE *fout = fopen ("secventa.out", "w");
int main (){

    fscanf (fin, "%d%d",&n, &k);
    for (i=1;i<=n;i++)
        fscanf (fin, "%d", &v[i]);
    p = 1;
    u = 1;
    d[1] = 1;
    maxim = -2000000;
    for (i=2;i<=n;i++){
        while (p<=u && v[i] < v[d[u]])
            u--;
        d[++u] = i;
        if (i-d[p] == k)
            p++;
        if (i>=k && v[d[p]] > maxim){
            maxim = v[d[p]];
            p1 = i-k+1;
            p2 = i;
        }

    }
    fprintf (fout, "%d %d %d",p1,p2,maxim);

    return 0;
}