Cod sursa(job #482924)

Utilizator popa.andreeaPopa Andreea Maria popa.andreea Data 6 septembrie 2010 10:53:25
Problema Secventa 3 Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.86 kb
# include <stdio.h>
# define q 32001
int a[q],b[q],c[q],d[q],e[q];
int n,p,u,i,last,x,y,x1,y1;
float f;
int main()
{
	freopen("secv3.in","r",stdin);
	freopen("secv3.out","w",stdout);
	scanf("%d%d%d",&n,&p,&u);
	for (i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		c[i]=c[i-1]+a[i];
	}
	for (i=1;i<=n;i++)
	{
		scanf("%d",&b[i]);
		d[i]=d[i-1]+b[i];
		e[i]=1;
	}
	last=0;
	for (i=1;i<=n;i++)
		if (a[i]>b[i])
			if (!last) last=i;
				else 
				if (u>i-last+e[i]) last=i;
					else
					if (p>i-last+e[i] && c[i]-c[last-1]>=d[i]-d[last-1]) 
					{
						x1=(c[i]-c[last-1]);
						y1=(d[i]-d[last-1]);
						x=(x1)*b[i];
						y=(y1)*a[i];
						if (x>y) 
						{
							a[i]=x1;
							b[i]=y1;
							e[i]+=i-last;
						}
						last=i;
					}
	x=1;
	for (i=2;i<=n;i++)
		if (a[x]*b[i]<b[x]*a[i]) x=i;
	f=(float)a[x]/b[x];
	printf("%.2f",f);
}