Cod sursa(job #346365)

Utilizator exquisiteDamian Alexandru exquisite Data 7 septembrie 2009 15:50:09
Problema Secventa Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.67 kb
#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

#define N_MAX 500001

int main() {
	long n, k, x, i, q[N_MAX], pq = 0, uq = 0, max = -60000, pmax = -1;
	long v[N_MAX];
	ifstream fin;
	ofstream fout;

	fin.open("secventa.in");
	fout.open("secventa.out");

	fin >> n >> k;

	for (i = 0; i < n; i++) {
		fin >> x;
		v[i] = x;
		for (; uq != pq && q[uq - 1] > x; uq--);
		q[uq++] = x;
		if (i == k-1) max = q[pq], pmax = i;
		if (i >= k) {
			if (v[i - k] == q[pq]) pq++;
			if (q[pq] > max) max = q[pq], pmax = i;
		}
	}
	fout << pmax - k + 2 << " " << pmax + 1 << " " << max <<"\n";
	fin.close();
	fout.close();
	return 0;
}