Cod sursa(job #812925)

Utilizator blechereyalBlecher Eyal blechereyal Data 14 noiembrie 2012 18:14:33
Problema Secventa Scor 70
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=-30000;
    pos=0;
    for(i=1;i<=n;++i)
		f>>v[i];
    
	for(i=1;i<=n;++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;
	
	return 0;
}