Cod sursa(job #438633)

Utilizator ati90atiNagy Attila ati90ati Data 10 aprilie 2010 22:11:21
Problema Secventa Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.69 kb
#include <stdio.h>
#include <stdlib.h>

int d[500000],a[500000];

int main()
{
	FILE* f1;
	f1=(fopen("secventa.in","r"));
	int n,k;
	fscanf(f1,"%d %d\n",&n,&k);

	int eleje=0,vege=0,min_hely=0;

	for (int i=0;i<n;i++)
	{
		fscanf(f1,"%d",&a[i]);
	}
	fclose(f1);

	int min=-30001;

	for (int i=0;i<n;i++)
	{
		{
			if (d[eleje]<=i-k)
				++eleje;
			while ((eleje<=vege) && (a[i]<a[d[vege]]))
				--vege;
			++vege;
			d[vege]=i;

			if (i>=k-1)
				if (min<a[d[eleje]])
				{
					min=a[d[eleje]];
					min_hely=i;
				}
		}
	}

	FILE* f2;
	f2=(fopen("secventa.out","w"));

	fprintf(f2,"%d %d %d\n",min_hely-k+2,min_hely+1,min);

	fclose(f2);
	return 0;
}