Cod sursa(job #778479)

Utilizator adascaluAlexandru Dascalu adascalu Data 14 august 2012 21:00:38
Problema Secventa Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.91 kb
using namespace std;
#include<fstream>
#include<deque>
#include<algorithm>
#define inF "secventa.in"
#define outF "secventa.out"
#define INF 32000
int main ()
{
	int n,k,i=0,x,min=INF,inf ,sup;
	deque<int>v;
	pair<int,pair<int,int> > rez1;
	rez1.first=INF;
	ifstream f(inF);
	f>>n>>k;
	rez1.second.first=inf=1;
	rez1.second.second=sup=k;
	for(i=1;i<=k;i++)
	{
		f>>x;
		if(x<min)
			min=x;
		while(x<=*v.end() && v.size()!=1)
			v.pop_back();
		v.push_back(x);
	}
	i=k;
	rez1.first=min;
	while(i!=n)
	{
		f>>x;
		v.pop_front();
		while(x<=*v.end() &&v.size()!=1)
			v.pop_back();
		v.push_back(x);
		min=*min_element(v.begin(),v.end());
		i++,inf++,sup++;
		if(min>rez1.first)
		{
			rez1.first=min;
			rez1.second.first=inf;
			rez1.second.second=sup;
		}
	}
	f.close();
	ofstream g(outF);
	g<<rez1.second.first<<" "<<rez1.second.second<<" "<<rez1.first;
	g.close();
	return 0;
}