Cod sursa(job #21552)

Utilizator amadaeusLucian Boca amadaeus Data 23 februarie 2007 20:37:50
Problema Secventa Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.65 kb
#include <fstream>
#include <deque>

using namespace std;

typedef pair< int, int > p;

int main() {
	deque< p > d;
	p x;
	int best = -66666, poz, N, K;
	
	ifstream Fin( "secventa.in" );
	ofstream Fout( "secventa.out" );

	Fin >> N >> K;
	Fin >> x.second;
	x.first = 1;
	d.push_back( x );
	for( int i=2; i<=N; i++ ) {
		if( d.front().first <= i-K )
			d.pop_front();

		Fin >> x.second;
		x.first = i;

		while( d.back().second >= x.second )
			d.pop_back();
		d.push_back( x );

		if( best < d.front().second ) {
			poz = i;
			best = d.front().second;
		}
	}
	Fout << poz - K + 1 << " " << poz << " " << best;
	return 0;
}