Cod sursa(job #1098624)

Utilizator NaniteNanite Nanite Data 4 februarie 2014 22:42:30
Problema Secventa 3 Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.21 kb
#include <cstdio>
#include <algorithm>

const int maxL = 30000, maxU = maxL, maxN = maxL;
int L, U, N;
float *answer = nullptr;

struct item {
    int price, time;
    float value() {
        return (float)price/time;
    }
}items[maxU];

void read() {
    scanf("%i%i%i", &N, &L, &U);
    for(int i = 0; i < N; i++) {
        scanf("%i", &items[i].price);
    }
    for(int i = 0; i < N; i++) {
        scanf("%i", &items[i].time);
    }
}

bool cmp(item a, item b) {
    return a.value() > b.value();
}

void tryAnswer(float a) {
    if(answer == nullptr) {
        answer = new float(a);
    } else if (a > *answer){
        (*answer) = a;
    }
}

void process() {
    int priceBuffer, timeBuffer;
    for(int a = L; a < U; a++) {
        for(int c = 0; c < N-a+1; c++) {
            priceBuffer = timeBuffer = 0;
            for(int b = c; b < a + c; b++) {
                priceBuffer += items[c].price;
                timeBuffer += items[c].time;
            }
            tryAnswer((float)priceBuffer/timeBuffer);
        }
    }
}

void write() {
    printf("%.2f", *answer);
}

int main() {
    freopen("secv3.in", "r", stdin);
    freopen("secv3.out", "w", stdout);

    read();
    process();
    write();


    return 0;
}