Pagini recente » Cod sursa (job #3131011) | Cod sursa (job #3227689) | Cod sursa (job #1266727) | Cod sursa (job #3252615) | Cod sursa (job #1098624)
#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;
}