Cod sursa(job #2464748)

Utilizator bluestorm57Vasile T bluestorm57 Data 28 septembrie 2019 21:16:25
Problema Secventa 3 Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.89 kb
#include <bits/stdc++.h>

using namespace std;

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

const int NMAX = 30005;
int n,mn,mx,t[NMAX],c[NMAX];
double ans, ans2, ans3;

int main(){
    int i,j;
    f >> n >> mn >> mx;
    for(i = 1 ; i <= n ; i++)
        f >> c[i];
    for(i = 1 ; i <= n ; i++)
        f >> t[i];

    for(i = 2 ; i <= n ; i++){
        c[i] += c[i - 1];
        t[i] += t[i - 1];
    }

    ans = c[mn] * 1.0 / (t[mn] * 1.0);
    i = 1;
    for(j = mn + 1 ; j <= n ; j++){
        if(j - i == mx - 1)
            i++;
        ans3 = 1.0 * (c[j] - c[i - 1]) / (1.0 * (t[j] - t[i - 1]));
        ans2 = 1.0 * (c[j] - c[i - mn]) / (1.0 * (t[j] - t[i - mn]));
        if(ans2 > ans3)
            j = i - mn + 1;
        if(t[j] - t[i - 1])
            ans = max(ans, max(ans2, ans3));
    }
    g << fixed << setprecision(4) << ans;
    return 0;
}