Cod sursa(job #70069)

Utilizator zobicaMarin Marin zobica Data 4 iulie 2007 18:55:50
Problema Secventa Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.9 kb
#include<fstream>

using namespace std;

int a[500000];
long k, n, pmax, pi, ps;

void citire(){
	ifstream fin("secventa.in");
	fin >> n >> k;
	for (int i=0;i<n;i++)
		fin >> a[i];
	fin.close();
}

long posmin(long pic, long &psc) {
	long pm = pic; 
	psc = pic + k;
	for (long i = pm; i < psc; i++)
		if(a[pm] > a[i])
			pm = i;
	while (psc <= n && a[psc - 1] == a[pm])
		psc++;
	return pm;
}

void rezolva() {
	int max = -30001;
	
	pi = 0;	

	long pic = 0, psc;
	long i = posmin(0, psc);	
	pmax = i;
	pi = pic; 
	ps = psc;	
	while (pic <= n - k) {
		long j = posmin(pic, psc);
		if (a[j] > a[pmax]) {
			pmax = j;
			pi = pic; 
			ps = psc;	
		}
		if ( j == pic)
			j++;
		pic = j;
	}
}


void scrie(){
	ofstream fout("secv.out");
	fout << pi + 1 << " " << ps << " " << a[pmax];
	fout.close();
}

int main() {
	citire();
	rezolva();
	scrie();
	return 0;
}