Cod sursa(job #1313952)

Utilizator thesvcoolmanLucian Bicsi thesvcoolman Data 11 ianuarie 2015 12:48:46
Problema Secventa 3 Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.05 kb
#include<fstream>
#include<vector>
#include<iomanip>

using namespace std;

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

struct Elem {
    int c, t;
    Elem(int a, int b) {c = a; t = b;}
    Elem() {}
};
vector<Elem> S;
int n, l, u;

Elem sum(const Elem &a, const Elem &b) {
    return Elem(a.c+b.c, a.t+b.t);
}
Elem dif(const Elem &a, const Elem &b) {
    return Elem(a.c-b.c, a.t-b.t);
}

int main() {
    fin>>n>>l>>u;
    int c, t;
    S.resize(n+1);
    S[0].c = S[0].t = 0;
    for(int i=1; i<=n; i++) {
        fin>>S[i].c;
        S[i].c += S[i-1].c;
    }
    for(int i=1; i<=n; i++) {
        fin>>S[i].t;
        S[i].t += S[i-1].t;
    }
    Elem e;
    double best = -1;
    int i, j;
    for(i=0; i<=n-u; i++)
    for(j=i+l; j<=i+u; j++) {
        e = dif(S[j], S[i]);
        best = max(best, ((double)e.c/e.t));
    }

    for(; i<=n-l; i++)
    for(j=i+1; j<=n; j++) {
        e = dif(S[j], S[i]);
        best = max(best, ((double)e.c/e.t));
    }
    fout<<setprecision(2)<<best;
    return 0;
}