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?
Input
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).
Output
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.
Examples
Input
1 100
1
40
Output
40.0
Input
2 100
1 1
25 30
Output
50.0
Input
2 100
1 1
60 60
Output
100.0
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
We are given: n ingredients, proportions a1,...,an (integers 1..100). We have b1,...,bn litres available. We want to choose a non-negative x such that we take ai * x litres of each ingredient i (i=1..n). However, we cannot take more than bi of each ingredient: so we require ai * x ≤ bi for all i. Also, the total soup volume (which is the sum of the taken ingredients) is sum_i (ai * x) = x * sum_i ai. But is that the volume? The soup is made by mixing the ingredients; presumably the volume equals the sum of volumes, assuming no volume change. So total volume = x * A, where A = sum a_i. Also we have a pan of capacity V litres, so the total volume must not exceed V: x * A ≤ V. Actually it says: "in a V litres volume pan (which means the amount of soup cooked can be between 0 and V litres)." So we can cook any amount up to V. So we want to maximize the soup volume (x * A) subject to constraints: x >= 0, ai * x ≤ bi for each i, and x * A ≤ V. So the maximum possible soup volume is min( V, min_i (bi / ai) * A )? Actually, x can be at most min_i (bi / ai) from the ingredient constraints. Then total volume = x * A ≤ min_i (bi / ai) * A. Also must be ≤ V. So the maximum total volume = min( V, min_i (bi / ai) * A ). But careful: The x that gives the ingredient constraints is x_max = min_i (bi / ai). Then total volume = A * x_max. However, we might be able to take a smaller x if the pan capacity is lower, but we want to maximize. So the answer = min( V, A * min_i (bi / ai) ). But is that correct? Let's test examples:
Example 1: n=1, V=100, a1=1, b1=40. Then A=1, min_i (b1/a1)=40, A * min = 40. min(100,40)=40. Output 40.0. OK.
Example 2: n=2, V=100, a=[1,1], b=[25,30]. A=2, min_i = min(25/1,30/1)=25. A*min = 50. min(100,50)=50. Output 50.0. OK.
Example 3: n=2, V=100, a=[1,1], b=[60,60]. min_i = 60, A*min=120, min(100,120)=100. Output 100.0. OK.
So seems straightforward.
But wait: The problem statement says: "consists of n ingredients that have to be mixed in proportion a1,...,an 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?" So indeed we pick x to maximize total volume, with constraints.
Thus answer = min(V, sum_i a_i * (min_j (b_j / a_j) )? But careful: The maximum x is limited by each ingredient: x ≤ b_i / a_i for all i. So x_max = min_i b_i / a_i. Then total volume = x_max * sum a_i. But we also cannot exceed V, so if that exceeds V, we can only fill the pan: then total volume = V, but we need to check if we can actually achieve exactly V? The pan capacity is V; we can cook any amount up to V. So if we have enough ingredients to exceed V, we can just take x such that x * sum a_i = V, provided that x ≤ min_i b_i / a_i. That requires V / sum a_i ≤ min_i b_i / a_i, i.e., V ≤ sum a_i * min_i b_i / a_i. So if V is less than that maximum possible volume, we can achieve exactly V (since we can reduce x accordingly). So answer = min(V, sum a_i * min_i b_i / a_i). So indeed answer is that.
But note: There is a subtlety: The a_i are integers but the ratio b_i/a_i may not be integer. That's fine. x can be any real non-negative. So answer is continuous.
Thus the solution is straightforward: read n, V; read a array; read b array; compute A = sum a_i. Compute min_ratio = INF large; for i in 0..n-1: min_ratio = min(min_ratio, b_i / a_i). Then max_vol = A * min_ratio. Answer = min(V, max_vol). Print with appropriate precision.
But wait: Could there be any other constraints? The pan capacity is V; we can cook any amount between 0 and V. So indeed we can stop at V. So answer as above.
But is it always possible to achieve exactly min(V, max_vol)? If V is less than max_vol, then we need x = V / A, which must satisfy x ≤ min_i b_i/a_i. This holds if V/A ≤ min_i b_i/a_i => V ≤ A*min_i b_i/a_i = max_vol. So yes. So we can achieve exactly V. If V is greater than max_vol, then we take x = min_ratio, giving total volume = max_vol, which is ≤ V. So we can achieve that.
Thus answer is min(V, max_vol).
Edge cases: If some a_i = 0? But a_i >=1 per constraints. So no division by zero. b_i can be 0, so min_ratio can be 0, then answer 0. That's fine.
Precision: We need absolute or relative error < 1e-4. So we can print with e.g., 10 decimal places.
Implementation: Use double.
Thus problem is solved.
But is there any nuance? The problem statement says: "in a V litres volume pan (which means the amount of soup cooked can be between 0 and V litres)". That suggests we can produce any volume less than or equal to V. So yes.
Thus the solution is trivial.
But wait, maybe there is a twist: The soup is made by mixing in proportion a_i, but the volumes of ingredients might not simply add to the soup volume? Usually borscht is cooked, maybe volume changes due to boiling etc. But the problem likely treats it as the sum of volumes. And the examples match.
So final answer: compute answer = min(V, sum(a_i) * min_i(b_i/a_i)). Print.
Now think about reading input: n and V are integers. a_i and b_i are integers. We can compute with doubles.
Complexity: O(n). n <= 20, V <= 10000.
Thus solution.
I'll produce a Python solution: read ints, compute as float, print answer with e.g. print("{:.10f}".format(ans)) to be safe.
But maybe the output format expects without extra trailing zeros? Usually it's okay. Example outputs show "40.0". So printing with one decimal might be okay, but better to print with enough digits.
Now, I'll write the solution accordingly.
But hold on: There is a possibility that the pan capacity V could be less than the sum of minimal amounts? Actually, if we take x such that total = V, we might need to adjust ingredient amounts to maintain proportion. That is possible as long as each ai * (V/A) <= bi. Since V <= max_vol, then V/A <= min_i(b_i/a_i) implies ai*(V/A) <= bi. So it's fine.
Thus answer.
However, let me double-check the problem text: "This should also improve his algebra skills." "According to the borscht recipe it consists of n ingredients that have to be mixed in proportion a1, ..., an litres (thus, there should be a1 ·x, ..., an ·x litres of corresponding ingredients mixed for some non-negative x)." This is exactly as we assumed.
Thus final answer: print min(V, total_a * min_ratio).
Now, I'll write the final message: Provide solution in Python.
Implementation steps:
def solve():
import sys
data = sys.stdin.read().strip().split()
if not data: return
it = iter(data)
n = int(next(it))
V = int(next(it))
a = [int(next(it)) for _ in range(n)]
b = [int(next(it)) for _ in range(n)]
total_a = sum(a)
min_ratio = float('inf')
for i in range(n):
ratio = b[i] / a[i]
if ratio < min_ratio:
min_ratio = ratio
max_possible = total_a * min_ratio
ans = min(V, max_possible)
# Print with required precision
print("{:.10f}".format(ans))
That's it.
But I recall that some solutions may output like "40.0" without many decimals. But the judge usually accepts any with enough precision. So fine.
Now, I'll produce final answer. ```python
import sys
def solve() -> None:
data = sys.stdin.read().strip().split()
if not data:
return
it = iter(data)
n = int(next(it))
V = int(next(it))
a = [int(next(it)) for _ in range(n)]
b = [int(next(it)) for _ in range(n)]
code
total_a = sum(a)
min_ratio = float('inf')
for i in range(n):
ratio = b[i] / a[i] # a[i] >= 1, no division by zero
if ratio < min_ratio:
min_ratio = ratio
max_possible = total_a * min_ratio
answer = min(V, max_possible)
# Print with enough digits to satisfy 10^-4 error requirement
print("{:.10f}".format(answer))