Cod sursa(job #778836)

Utilizator adascaluAlexandru Dascalu adascalu Data 15 august 2012 23:00:17
Problema Secventa Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.87 kb
using namespace std;
#include<fstream>
#include<deque>
#include<set>
#include<algorithm>
#define pair pair<int,int>
#define mp make_pair
int main ()
{
	int n,k,i=0,x,rezmin=32000,rezsup,rezinf;
	deque<pair> v;
	set<int> heap;
	ifstream f("secventa.in");
	f>>n>>k;
	for(i=1;i<=k;i++)
	{
		f>>x;
		while(!v.empty() && x<v.back().first)
			v.pop_back();
		v.push_back(mp(x,i));
		if(x<rezmin)
		{
			rezmin=x;
			rezsup=v.back().second;
			rezinf=v.front().second;
		}
	}
	i=k;
	while(i!=n)
	{
		i++,f>>x;
		while(!v.empty() && x<v.back().first)
			v.pop_back();
		v.push_back(mp(x,i));
		if(v.back().second-v.front().second==k)
			v.pop_front();
		
		if(v.front().first>rezmin)
			rezmin=v.front().first,rezsup=v.back().second,rezinf=v.front().second;
	}
	f.close();
	ofstream g("secventa.out");
	g<<rezinf<<" "<<rezsup<<" "<<rezmin;
	return 0;
}