Algorithm
It's a very unfortunate day for Volodya today. He got bad mark in algebra and was therefore forced to do some work in the kitchen, namely to cook borscht (traditional Russian soup). This should also improve his algebra skills.
According to the borscht recipe it consists of n ingredients that have to be mixed in proportion litres (thus, there should be a1 ·x, ..., an ·x litres of corresponding ingredients mixed for some non-negative x). In the kitchen Volodya found out that he has b1, ..., bn litres of these ingredients at his disposal correspondingly. In order to correct his algebra mistakes he ought to cook as much soup as possible in a V litres volume pan (which means the amount of soup cooked can be between 0 and V litres). What is the volume of borscht Volodya will cook ultimately?
The first line of the input contains two space-separated integers n and V (1 ≤ n ≤ 20, 1 ≤ V ≤ 10000). The next line contains n space-separated integers ai (1 ≤ ai ≤ 100). Finally, the last line contains n space-separated integers bi (0 ≤ bi ≤ 100).
Your program should output just one real number — the volume of soup that Volodya will cook. Your answer must have a relative or absolute error less than 10 - 4.
1 100
1
40
40.0
2 100
1 1
25 30
50.0
2 100
1 1
60 60
100.0
Code Examples
#1 Code Example with C++ Programming
Code -
C++ Programming
#include <cstdio>
#include <vector>
int main(){
long n, V; scanf("%ld %ld\n", &n, &V);
std::vector<double> a(n, 0);
std::vector<double> b(n, 0);
double propSum(0);
for(long p = 0; p < n; p++){
scanf("%lf", &a[p]);
propSum += a[p];
}
for(long p = 0; p < n; p++){scanf("%lf", &b[p]);}
double x = V / propSum;
for(long p = 0; p < n; p++){
double ratio = b[p] / a[p];
if(ratio < x){x = ratio;}
}
printf("%.5lf\n", propSum * x);
return 0;
}
Copy The Code &
Try With Live Editor
Input
1
40
Output
Demonstration
CodeForces Solution-A. Guilty — to the kitchen!-Solution in C, C++, Java, Python