Cod sursa(job #2040080)

Utilizator cristii2000cristiiPanaite Cristian cristii2000cristii Data 15 octombrie 2017 13:22:20
Problema Secventa 3 Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.96 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;
}