Cod sursa(job #648027)

Utilizator ELHoriaHoria Cretescu ELHoria Data 12 decembrie 2011 22:21:21
Problema Secventa Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.53 kb
#include <fstream>

using namespace std;

ifstream fin("secventa.in");
ofstream fout("secventa.out");

int N , K , bk ,fr , pos , posf;
short A[500001] , dq[500001] ,bmax = -30005;

int main()
{
	fin>>N>>K;
	fr = 1; bk = 0;
	for(int i = 1;i<=N;++i)
	{
		fin>>A[i]; 
		while(fr<=bk && A[i] <= A[dq[bk]]) bk--;
		dq[++bk] = i;
		if(dq[fr] <= i - K)  fr++;
		if(i>=K) 
		{
			if(bmax < A[dq[fr]])
				bmax = A[dq[fr]] , pos = dq[fr];
		}
	}
	posf = pos + K - 1;
	fout<<pos<<" "<<posf<<" "<<bmax;
	return 0;
}