Cod sursa(job #2041144)

Utilizator dragomirmanuelDragomir Manuel dragomirmanuel Data 16 octombrie 2017 21:31:16
Problema Secventa 3 Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.96 kb
#include <iostream>
#include <fstream>

using namespace std;

ifstream fin("secv3.in");
ofstream fout("secv3.out");

const int NMax = 30005;
const int EPS = 0.001;
int L, U, N;
int c[NMax], t[NMax];

void Read()
{
    fin >> N >> L >> U;
    int x;
    for(int i=1; i<=N; ++i)
    {
        fin >> x;
        c[i] = x + c[i-1];
    }

    for(int i=1; i<=N; ++i)
    {
        fin >> x;
        t[i] = x + t[i-1];
    }
}

void Greedy()
{
    double rez = 1.0 * c[L] / t[L];
    int j = 1;

    for(int i = L+1; i <= N ; ++i)
    {
        if(i - L == U)
            ++j;

        double t1 = 1.0 * (c[i] - c[j-1]) / (t[i] - t[j-1]);
        double t2 = 1.0 * (c[i] - c[i-L]) / (t[i] - t[i-L]);

        if(t1 - t2 < EPS)
        {
            t1 = t2;
            j = i - L + 1;
        }

        rez = max(rez, t1);
    }

    fout << rez;
}

using namespace std;

int main()
{
    Read();
    Greedy();
    return 0;
}