Cod sursa(job #2196428)

Utilizator MrJ33FGroza Cosmin MrJ33F Data 19 aprilie 2018 11:34:09
Problema Secventa 3 Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.98 kb
#include <cstdio>
#include <iostream>

using namespace std;

int n, l, u, i, j, nr;

double rez, now, ante, costuri[30005], times[30005];

void citire()
{
    scanf("%d %d %d\n",&n, &l, &u);

    for(i = 1; i <= n; i++)
    {
        scanf("%d ", &nr);
        costuri[i] = costuri[i-1] + nr;

    }
    for(i = 1; i <= n; i++)
    {
        scanf("%d ", &nr);
        times[i] = times[i-1] + nr;
    }
}

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

    citire();

    rez = costuri[l] / times[l];

    j = 1;

    for(i = l+1; i <= n; i++)
    {
        if(i - l == u)
            j++;

        ante = (costuri[i] - costuri[j-1]) / (times[i] - times[j-1]);
        now = (costuri[i] - costuri[i-l]) / (times[i] - times[i-l]);

        if(ante < now)
        {
            ante = now;
            j = i - l + 1;
        }
        rez = max(rez, ante);


    }
    printf("%.2lf", rez);

    return 0;
}