Cod sursa(job #2109396)

Utilizator pimao2004Lupu Stefan Dragos pimao2004 Data 19 ianuarie 2018 17:57:31
Problema Secventa 3 Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.75 kb
#include <fstream>
#include <iomanip>
using namespace std;
ifstream in ("secv3.in");
ofstream out ("secv3.out");
int cost[30001],timp[30001];
int n;
double val(int lung)
{
    double ma=0,x;
    int i;
    for(i=lung; i<=n; i++)
    {
        x=(1.00*cost[i]-cost[i-lung])/(1.00*timp[i]-timp[i-lung]);
        if(x>ma)
            ma=x;
    }
    return ma;
}
int main()
{
    int l,u;
    in>>n>>l>>u;
    int i;
    for(i=1;i<=n;i++)
        in>>cost[i],cost[i]+=cost[i-1];
    for(i=1;i<=n;i++)
        in>>timp[i],timp[i]+=timp[i-1];
    int lg;
    double ma=0;
    double x;
    for(lg=l;lg<=u;lg++)
    {
        x=val(lg);
        if(ma<x)
            ma=x;
    }
    out<<fixed<<setprecision(2)<<ma;
    return 0;
}