Cod sursa(job #1413849)

Utilizator CosminRusuCosmin Rusu CosminRusu Data 2 aprilie 2015 09:59:46
Problema Secventa Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.68 kb
#include <iostream>
#include <fstream>
#include <deque>

using namespace std;

const int maxn = 500005;
const int oo = 0x3f3f3f3f;

int a[maxn], n, k, _st, _end;

int main() {
	ifstream fin("secventa.in");
	ofstream fout("secventa.out");
	fin >> n >> k;
	int _bestmax = -oo;
	deque <int> dq;
	for(int i = 1 ; i <= n ; ++ i) {
		fin >> a[i];
		while(!dq.empty() && a[dq.back()] >= a[i])
			dq.pop_back();
		dq.push_back(i);
		if(dq.front() <= i - k)
			dq.pop_front();
		if(i >= k) {
			if(_bestmax < a[dq.front()]) {
				_bestmax = a[dq.front()];
				_st = dq.front();
				_end = i;
			}
		}
	}
	while(a[_st - 1] >= _bestmax) {
		-- _st;
	}
	fout << _st << ' ' << _end << ' ' << _bestmax << "\n";
}