Cod sursa(job #813304)

Utilizator blechereyalBlecher Eyal blechereyal Data 15 noiembrie 2012 10:13:37
Problema Secventa Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.54 kb
//secventa
#include <fstream>
using namespace std;

int n, k, v[5000001], dq[5000001], p=1, u=0;

int main()
{   int max,pos;
    ifstream f("secventa.in");
    ofstream g("secventa.out");
	int i;
    
	f>>n>>k;
	max=-1<<31;
    pos=0;
    
	for(i=1;i<=n;++i)
	{
		f>>v[i];
		while(p<=u && v[i]<=v[dq[u]])
			--u;
		dq[++u]=i;
		if(dq[p]==i-k)
			++p;
		if ((i>=k)&&(max<v[dq[p]])) {max=v[dq[p]];
                                    pos=i; }
	}
	
	g<<pos-k+1<<" "<<pos<<" "<<max;
	
	f.close();
	g.close();
	
	return 0;
}