Cod sursa(job #849533)

Utilizator KONT_testekobol Vasile KONT_teste Data 7 ianuarie 2013 09:32:04
Problema Secventa Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.7 kb
#include<cstdio>
#include<queue>
using namespace std;
const int Nmax = 500001;
int n, k, a[Nmax],pb,vb;
deque <int> d;
int main()
{
	freopen("secventa.in", "r", stdin); 
	freopen("secventa.out", "w", stdout);
	scanf("%d %d ", &n, &k);
    for(int i=1; i<=n; ++i) scanf("%d ", &a[i]);
	for(int i=1; i<=k; ++i)
	{
		while(!d.empty() &&  a[i] <= a[d.front()]) d.pop_front();
	    d.push_back(i);
	}
	vb=a[d.front()];
	pb=k;
	for(int i=k+1; i<=n; ++i)
	{	if(d.front()==i-k) d.pop_front();
		while(!d.empty() &&  a[i] <= a[d.front()]) d.pop_front();
	    d.push_back(i);
		if(a[d.front()]>vb)
		{
			vb=a[d.front()];
			pb=i;
		}
	}
	printf("%d %d %d\n", pb-k+1,pb,vb);
    return 0;
}