Cod sursa(job #346681)

Utilizator chera_laryCHERA Laurentiu chera_lary Data 9 septembrie 2009 01:21:15
Problema Secventa Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <fstream>
#define fin "secventa.in"
#define fout "secventa.out"
#define nMax 500001
#define Inf 30001
#define min(a,b) (a<b)?a:b

using namespace std;

int n,k,poz;
int s[nMax], c[nMax];

void citeste(){
	fstream in(fin, ios::in);
	in>>n>>k;
	for(int i=1;i<=n;i++)
		in>>s[i];
	in.close();
}

void doProcess(){
	int minimum=Inf; 
	poz=n-k+1;
	for(int i=n;i>n-k;i--)
		if(minimum>s[i])
			minimum=s[i];
	c[n-k+1]=minimum;
	for(int i=n-k;i>0;i--){
		c[i]=min(s[i],c[i+1]);
		if(c[i]>c[poz])
			poz=i;
	}
}

void tipar(){
	fstream out(fout, ios::out);
	out<<poz<<" "<<poz+k-1<<" "<<c[poz]<<endl;
	out.close();
}

int main(void){
	citeste();
	doProcess();
	tipar();
	return 0;
}