Cod sursa(job #1455839)

Utilizator fluture.godlikeGafton Mihnea Alexandru fluture.godlike Data 29 iunie 2015 11:36:26
Problema Secventa Scor 0
Compilator cpp Status done
Runda mpractice1 Marime 0.98 kb
#include <cstdio>
#define DIM 10007
#define NMAX 500007
#define inf -100007
using namespace std;
FILE *fin, *fout;
int n, k, st = 1, dr = 0, maxn = inf, pos, temp;
struct pdeque
{
    int v;
    int p;
} dq[NMAX];
int main()
{
    fin = freopen("secventa.in", "r", stdin);
    fout = freopen("secventa.out", "w", stdout);
    scanf("%d%d", &n, &k);
    for(int i = 1; i< k; i++)
    {
        scanf("%d", &temp);
        while(dr >= st && temp < dq[dr].v) dr--;
        dr++;
        dq[dr].v = temp;
        dq[dr].p = i;
    }
    for(int i = k; i<= n; i++)
    {
        scanf("%d", &temp);
        while(dr >= st && temp < dq[dr].v) dr--;
        dr++;
        dq[dr].v = temp;
        dq[dr].p = i;
        if(dq[st].p + k <= dq[dr].p) st++;
        if(dq[st].v > maxn)
        {
            maxn = dq[st].v;
            pos = dq[st].p;
        }
    }
    printf("%d %d %d\n", pos, pos+k-1, maxn);
    fclose(fin);
    fclose(fout);
    return 0;
}