Cod sursa(job #778802)

Utilizator adascaluAlexandru Dascalu adascalu Data 15 august 2012 20:58:34
Problema Secventa Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.16 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;
		
		if(v.size()>1)
		while(x<v.back() && v.size()>1)
			v.pop_back();
		v.push_back(x);
	}
	i=k;
	rez1.first=min;
	int nr_ap_min=k,copy_top;
	copy_top=v.front();
	while(i<n)
	{
		f>>x;
		while(x<v.back() && v.size()>1)
			v.pop_back();
		v.push_back(x);
		if(nr_ap_min==k)
		{
			v.pop_front();
			nr_ap_min=0;
			copy_top=v.front();
		}
		if(copy_top==v.front())
			nr_ap_min++;
		else
		{
			copy_top=v.front();
			nr_ap_min=1;
		}
		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;
}