Cod sursa(job #1833958)

Utilizator pastoradrianPastor Adrian pastoradrian Data 23 decembrie 2016 16:06:28
Problema Secventa 3 Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.1 kb
#include <cstdio>

using namespace std;

int n, L, U, i, j;
int cost[30002], time[30002], sumCost[30002], sumTime[30002];
double ratio, max;

int main()
{
    freopen("secv3.in", "r", stdin);
    freopen("secv3.out", "w", stdout);

    scanf("%d %d %d", &n, &L, &U);

    for(i = 0; i < n; i++)
        scanf("%d", &cost[i]);
    for(i = 0; i < n; i++)
        scanf("%d", &time[i]);

    for(i = 0; i < n; i++)
    {
        for(j = 0; j < U && (i + j) < n; j++)
        {
            sumCost[i] += cost[i + j];
            sumTime[i] += time[i + j];
        }

        if(sumTime[i] != 0)ratio = (double) ((double)sumCost[i] / (double)sumTime[i]);
			if(ratio > max) max = ratio;
    }
    U--;

    while(U >= L)
    {
        for(i = 0; i <= n; i++)
        if((i + U) < n)
        {
            sumCost[i] -= cost[i + U];
            sumTime[i] -= time[i + U];
            if(sumTime[i] != 0) ratio = (double) ((double)sumCost[i] / (double)sumTime[i]);
            if(ratio > max) max = ratio;
        }

        U--;
    }

    printf("%.2f\n", max);
    return 0;
}