Cod sursa(job #1088969)

Utilizator GaborGabrielFMI - GabrielG GaborGabriel Data 21 ianuarie 2014 01:33:53
Problema Secventa Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.62 kb
#include <stdio.h>

#define MAXN 500005
int N, K;
int deq[MAXN], front = 1, back = 0;
int sir[MAXN];

int main()
{
	freopen("secventa.in", "r", stdin);
	freopen("secventa.out", "w", stdout);

	int i, inceput, sfarsit, maxim = -30005;

	scanf("%d %d", &N, &K);
	for (i = 1; i <= N; ++i)
	{
		scanf("%d", &sir[i]);
		while (front <= back && sir[deq[back]] > sir[i])
			back--;
		deq[++back] = i;
		if (deq[front] == i - K)
			front++;
		if (i >= K && sir[deq[front]] > maxim)
			maxim = sir[deq[front]], inceput = i - K + 1, sfarsit = i;
	}

	printf("%d %d %d\n", inceput, sfarsit, maxim);

	return 0;
}