Pagini recente » Cod sursa (job #1645329) | Cod sursa (job #118411) | Cod sursa (job #2945036) | Infoarena Monthly 2012 - Runda 5, Clasament | Cod sursa (job #16231)
Cod sursa(job #16231)
#include<stdio.h>
int main()
{
FILE *f=fopen("secv3.in", "r");
unsigned int n, l, u, cost[30002], timp[30002], i, j, k;
float rap, max, MAX;
long c, t;
fscanf(f, "%d%d%d", &n, &l, &u);
for(i=1; i<=n; i++)
fscanf(f, "%d", &cost[i]);
for(i=1; i<=n; i++)
fscanf(f, "%d", &timp[i]);
fclose(f);
cost[0]=timp[0]=0;
max=0;
MAX=0;
for(i=l; i<=n; i++)
{
c=0;
t=0;
for(j=i; j>=i-l+1; j--)
{
c=c+cost[j];
t=t+timp[j];
}
rap=(float)c/t;
max=rap;
for(k=j; k>=i-u+1 && k>=1; k--)
{
c=c+cost[k];
t=t+timp[k];
rap=(float)c/t;
if(rap>max)
max=rap;
}
if(max>MAX)
MAX=max;
}
f=fopen("secv3.out", "w");
fprintf(f, "%.2f", MAX);
fclose(f);
return 0;
}