Pagini recente » Arhiva de probleme | Cod sursa (job #42614) | Cod sursa (job #897566) | Clasament temadec2019 | Cod sursa (job #44414)
Cod sursa(job #44414)
#include <stdio.h>
float X,Y,fit,answer,z[2<<15];
int i,j,min,max,x[2<<15],y[2<<15],n;
void add()
{
i++;
X+=x[i];
Y+=y[i];
fit=X/Y;
}
void sub()
{
X-=x[j];
Y-=y[j];
j++;
fit=X/Y;
}
int main (void)
{
FILE *f=fopen("secv3.in","r");
fscanf(f,"%d %d %d",&n,&min,&max);
for(i=1;i<=n;i++) fscanf(f,"%d",&x[i]);
for(i=1;i<=n;i++) fscanf(f,"%d",&y[i]);
for(i=1;i<=n;i++) z[i]=(float)x[i]/(float)y[i];
fclose(f);
i=0;
for(j=1;j<=min;j++) add();
answer = fit;
i=min;
j=1;
do
{
if (i==n || i-j+1==max) sub();
else if (i-j+1==min) add();
else if (z[j]<fit) sub();
else if (z[i+1]>fit) add();
if (fit>answer) answer=fit;
// printf("(%d %d) %0.2f %0.2f/%0.2f\n",j,i,fit,X,Y);
}
while (j<=n-min+1);
f=fopen("secv3.out","w");
fprintf(f,"%.2f\n",answer);
fclose(f);
return 0;
}