Cod sursa(job #2259652)

Utilizator papinub2Papa Valentin papinub2 Data 13 octombrie 2018 16:29:20
Problema Secventa 3 Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.01 kb
#include <fstream>
#include <vector>
#include <algorithm>
#include <iomanip>

using namespace std;

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

int main()
{
    int n, lim_st, lim_dr;
    in >> n >> lim_st >> lim_dr;

    vector<double> cost(n + 1);
    vector<double> timp(n + 1);

    for (int i = 1; i <= n; i++)
    {
        int x;
        in >> x;
        cost[i] = cost[i - 1] + x;
    }

    for (int i = 1; i <= n; i++)
    {
        int x;
        in >> x;
        timp[i] = timp[i - 1] + x;
    }

    double rez = cost[lim_st] / timp[lim_st];

    int k = 1;
    for (int i = lim_st + 1; i <= n; i++)
    {
        if (i - lim_st == lim_dr)
            k++;

        double a = (cost[i] - cost[k - 1]) / (timp[i] - timp[k - 1]);
        double b = (cost[i] - cost[i - lim_st]) / (timp[i] - timp[i - lim_st]);

        if (b > a)
            k = i - lim_st + 1;

        rez = max(rez, max(a, b));
    }

    out << fixed << setprecision(2) << rez;
    return 0;
}