The World Programming Olympics Medal is a metal disk, consisting of two parts: the first…
- User
The World Programming Olympics Medal is a metal disk, consisting of two parts: the first part is a ring with outer radius of r1 cm, inner radius of r2 cm, (0 < r2 < r1) made of metal with density p1 g/cm3. The second part is an inner disk with radius r2 cm, it is made of metal with density p2 g/cm3. The disk is nested inside the ring.
The Olympic jury decided that r1 will take one of possible values of x1, x2, ..., xn. It is up to jury to decide which particular value r1 will take. Similarly, the Olympic jury decided that p1 will take one of possible value of y1, y2, ..., ym, and p2 will take a value from list z1, z2, ..., zk.
According to most ancient traditions the ratio between the outer ring mass mout and the inner disk mass min must equal , where A, B are constants taken from ancient books. Now, to start making medals, the jury needs to take values for r1, p1, p2 and calculate the suitable value of r2.
The jury wants to choose the value that would maximize radius r2. Help the jury find the sought value of r2. Value r2 doesn't have to be an integer.
Medal has a uniform thickness throughout the area, the thickness of the inner disk is the same as the thickness of the outer ring. Input
The first input line contains an integer n and a sequence of integers x1, x2, ..., xn. The second input line contains an integer m and a sequence of integers y1, y2, ..., ym. The third input line contains an integer k and a sequence of integers z1, z2, ..., zk. The last line contains two integers A and B.
All numbers given in the input are positive and do not exceed 5000. Each of the three sequences contains distinct numbers. The numbers in the lines are separated by spaces.
Output
Print a single real number — the sought value r2 with absolute or relative error of at most 10 - 6. It is guaranteed that the solution that meets the problem requirements exists.
Examples
Input
3 1 2 3 1 2 3 3 2 1 1 2
Output
2.683281573000
Input
4 2 3 6 4 2 1 2 3 10 6 8 2 1
Output
2.267786838055
Note
In the first sample the jury should choose the following values: r1 = 3, p1 = 2, p2 = 1.
Assistant
We need to parse problem carefully.
We have a medal: two parts: an outer ring (annulus) with outer radius r1, inner radius r2 (so ring's area = π (r1^2 - r2^2)). It's made of metal density p1. Inner disk of radius r2, made of metal density p2. Uniform thickness throughout, same thickness for both parts. So mass of outer ring = volume * density = (area * thickness) * p1 = thickness * p1 * π (r1^2 - r2^2). Similarly, mass of inner disk = thickness * p2 * π r2^2. The thickness is same constant, denote t. So m_out = t * π * p1 * (r1^2 - r2^2); m_in = t * π * p2 * r2^2.
The ratio m_out / m_in must equal something: from the problem description: "ratio between the outer ring mass mout and the inner disk mass min must equal , where A, B are constants taken from ancient books." The image likely is something like A / B? Or maybe a fraction? In the statement, there's placeholder . Typically such problems have ratio equal to A/B. Let's check examples.
First sample: Input: 3 1 2 3 1 2 3 3 2 1 // actually this line says: "3 3 2 1" meaning k=3, z1=3, z2=2, z3=1? Wait read: third line: integer k and sequence. So "3 3 2 1" means k=3 and numbers are 3,2,1? But the order given is "3 3 2 1" which suggests first number is 3 (k), then the three numbers: 3,2,1. So p2 values: 3,2,1. Last line: A=1, B=2.
Output: 2.683281573000
We need to test if ratio m_out/m_in = A/B? That would be m_out/m_in = 1/2.
But also could be something like m_out/m_in = A/(A+B) etc? But typical is A/B. Let's try.
Given r1 chosen from {1,2,3}, p1 from {2}, p2 from {3,2,1}. So p1 is forced to 2. So we can choose r1 and p2. We want to maximize r2. For each choice, we need to find r2 that satisfies the ratio equation. The equation (with t, π cancelling) yields:
p1 * (r1^2 - r2^2) / (p2 * r2^2) = A / B? So
p1 (r1^2 - r2^2) / (p2 r2^2) = A / B => Cross multiply:
B * p1 * (r1^2 - r2^2) = A * p2 * r2^2
=> B p1 r1^2 - B p1 r2^2 = A p2 r2^2
=> B p1 r1^2 = r2^2 (A p2 + B p1)
=> r2^2 = (B p1 r1^2) / (A p2 + B p1)
=> r2 = r1 * sqrt( (B p1) / (A p2 + B p1) )
Wait check: r2^2 = (B p1 r1^2) / (A p2 + B p1). Yes.
Thus r2 = r1 * sqrt( (B p1) / (A p2 + B p1) ) = r1 * sqrt( B p1 / (A p2 + B p1) ).
Alternatively, we could also rearrange for ratio m_out/m_in = something else. But given typical, that seems plausible.
Now check with sample. For the output r2 ≈ 2.683281573. Which is > r1? r1 max is 3. So r2 cannot exceed r1 (since r2 < r1 by definition). So r2 approx 2.68 < 3, okay.
Now we can test which combination yields that r2. Let's compute possible r2 values.
List:
r1 options: 1,2,3. p1=2. p2 options: 3,2,1. A=1, B=2.
Compute r2 for each:
Formula: r2 = r1 * sqrt( B * p1 / (A * p2 + B * p1) ) = r1 * sqrt(22 / (1p2 + 2*2)) = r1 * sqrt(4 / (p2 + 4))
So:
p2=3: sqrt(4/7)= sqrt(0.57142857)=0.755928946; then r2 for r1=1 =>0.7559, r1=2=>1.51186, r1=3=>2.26779
p2=2: sqrt(4/6)= sqrt(2/3)=0.81649658; r1=1=>0.8165, r1=2=>1.63299, r1=3=>2.44949
p2=1: sqrt(4/5)= sqrt(0.8)=0.894427191; r1=1=>0.8944, r1=2=>1.78885, r1=3=>2.68328
The maximum r2 among these is r2=2.68328 for r1=3, p2=1. That matches output. So ratio appears to be A/B = 1/2. Good.
Second sample:
Input: 4 2 3 6 4 2 1 2 3 10 6 8 2 1
So r1 options: 2,3,6,4 (n=4) p1 options: 1,2 (m=2? Actually line: "2 1 2" meaning m=2, values 1 and 2) p2 options: 10,6,8 (k=3, numbers 10,6,8) A=2, B=1
Output: 2.267786838055
Now test with formula: r2 = r1 * sqrt( B p1 / (A p2 + B p1) ) = r1 * sqrt(1 * p1 / (2 p2 + 1 p1) ) = r1 * sqrt( p1 / (2 p2 + p1) )
We need to find combination that gives maximum r2.
Compute all possibilities:
r1 list: 2,3,4,6 p1: 1,2 p2: 10,6,8
Compute factor sqrt(p1/(2p2 + p1))
For p1=1: p2=10: sqrt(1/(20+1)=1/21) = sqrt(1/21)=0.21821789 p2=6: sqrt(1/(12+1)=1/13)= sqrt(1/13)=0.2773501 p2=8: sqrt(1/(16+1)=1/17)= sqrt(1/17)=0.2425356
For p1=2: p2=10: sqrt(2/(20+2)=2/22=1/11) = sqrt(1/11)=0.30151134 p2=6: sqrt(2/(12+2)=2/14=1/7)= sqrt(1/7)=0.37796447 p2=8: sqrt(2/(16+2)=2/18=1/9)= sqrt(1/9)=0.33333333
Now multiply by r1.
Compute r2 for each combination, keep max.
We'll compute:
p1=1:
r1=2: p2=10: 20.21821789=0.43643578 p2=6: 20.2773501=0.5547002 p2=8: 2*0.2425356=0.4850712
r1=3: p2=10: 30.21821789=0.65465367 p2=6: 30.2773501=0.8320503 p2=8: 3*0.2425356=0.7276068
r1=4: p2=10: 40.21821789=0.87287156 p2=6: 40.2773501=1.1094004 p2=8: 4*0.2425356=0.9701424
r1=6: p2=10: 60.21821789=1.3093073 p2=6: 60.2773501=1.6641006 p2=8: 6*0.2425356=1.4552136
p1=2:
r1=2: p2=10: 20.30151134=0.60302268 p2=6: 20.37796447=0.75592894 p2=8: 2*0.33333333=0.66666666
r1=3: p2=10: 30.30151134=0.90453402 p2=6: 30.37796447=1.13389341 p2=8: 3*0.33333333=1.0
r1=4: p2=10: 40.30151134=1.20604536 p2=6: 40.37796447=1.51185788 p2=8: 4*0.33333333=1.33333332
r1=6: p2=10: 60.30151134=1.80906804 p2=6: 60.37796447=2.26778682 p2=8: 6*0.33333333=2.0
Maximum among these: 2.26778682 (r1=6, p1=2, p2=6). Output is 2.267786838055 which matches. So ratio is A/B indeed.
Thus problem reduces to:
Given sets X = {x_i} (possible r1 values), Y = {y_i} (possible p1 values), Z = {z_i} (possible p2 values), and constants A, B > 0. Choose one element from each set (r1 from X, p1 from Y, p2 from Z) to maximize r2, where r2 = r1 * sqrt( (B * p1) / (A * p2 + B * p1) ).
Note: It's also required that 0 < r2 < r1 (since inner radius must be less than outer). The formula yields r2 < r1 automatically as sqrt factor <1 (since denominator > numerator). Also r2 > 0. So no other constraints.
Thus the problem is straightforward: iterate over all triples? Sizes: n,m,k <= 5000? Actually input says all numbers are positive and do not exceed 5000. But the number of elements? The sequences are given as integers, but the counts n, m, k are the first numbers in each line. The constraints might be that n,m,k can be up to maybe the length of the list? Could be up to 5000? But n,m,k themselves are not given explicit limits, but the numbers are ≤5000. Possibly n,m,k can be up to maybe 5000 each, because input size could be up to 15000 numbers plus counts. However, triple nested loop over up to 5000^3 = 125e9 would be impossible.
Thus we need to find a smarter way to maximize r2.
Observation: r2 = r1 * sqrt( B * p1 / (A * p2 + B * p1) ) = r1 * sqrt( 1 / ( 1 + (A p2)/(B p1) ) ) = r1 / sqrt( 1 + (A p2)/(B p1) ).
Alternatively, r2 = r1 * sqrt( B p1 ) / sqrt( A p2 + B p1 ). We want to maximize r2, so we want large r1, large p1, and small p2? Let's see monotonicity: For fixed r1 and p1, increasing p2 reduces r2 (denominator increases). For fixed r1 and p2, increasing p1 increases numerator sqrt(B p1) but also denominator sqrt(A p2 + B p1) increases. Actually we need to check monotonic in p1. Consider r2 as function of p1: f(p1) = r1 * sqrt( B p1 / (A p2 + B p1) ) = r1 * sqrt( B / ( A p2 / p1 + B ) ). As p1 increases, A p2 / p1 decreases, so denominator sqrt( A p2 / p1 + B ) decreases? Wait careful: Let g(p1) = sqrt( B p1 / (A p2 + B p1) ). Multiply numerator and denominator by 1/p1: sqrt( B / (A p2 / p1 + B) ). As p1 increases, A p2 / p1 decreases, so denominator sqrt(A p2/p1 + B) decreases, thus overall value sqrt( B / (something smaller) ) becomes larger. So r2 increases with p1.
Thus to maximize r2, we want largest possible r1, largest possible p1, smallest possible p2.
So naive: pick max r1 from X, max p1 from Y, min p2 from Z. That would give the maximum r2? Let's test with sample 1: max r1=3, max p1=2 (only), min p2=1 => gave max r2=2.68328. Indeed.
Sample 2: max r1=6, max p1=2, min p2=6? Wait min p2 from Z = {10,6,8} is 6. That yields r2=6 * sqrt(2/(26+2))=6sqrt(2/14)=6*sqrt(1/7)=6/√7≈2.2677868, which is indeed the maximum as computed. But could there be a scenario where using a slightly smaller r1 but a much smaller p2 yields larger r2? Or using a larger p1 with a larger p2 might not be as beneficial? Let's think more.
We want to maximize r2 = r1 * sqrt( B * p1 / (A * p2 + B * p1) ). Equivalent to maximize r2^2 = r1^2 * (B p1)/(A p2 + B p1) = r1^2 * 1 / (1 + (A p2)/(B p1)). So r2^2 = r1^2 / (1 + (A p2)/(B p1)). So for fixed r1, to maximize we want p2/p1 as small as possible. So among combinations, we want to minimize p2/p1 (since A,B constants positive). But also r1^2 factor matters. So we need to pick triple maximizing F(r1, p1, p2) = r1^2 * (B p1)/(A p2 + B p1). This is not simply independent. Could be that a slightly smaller r1 but with a much better p2/p1 ratio yields larger product? For instance, if we have r1 huge but p2/p1 also huge, might be worse than medium r1 with very small p2/p1. But note p2/p1 ratio: p2 from Z, p1 from Y. So we have discrete sets.
Thus the problem becomes: Choose i, j, k to maximize r1_i * sqrt( B * p1_j / (A * p2_k + B * p1_j) ). Since all numbers positive, we can consider maximizing r1_i^2 * (B p1_j) / (A p2_k + B p1_j).
We could attempt to reduce dimension by sorting or using monotonic properties. The expression can be rewritten: r2^2 = (B * r1^2) / (A * (p2/p1) + B). Actually: r2^2 = r1^2 * (B p1)/(A p2 + B p1) = r1^2 * B / (A (p2/p1) + B). So it's a function of r1 and ratio (p2/p1). So for a given ratio R = p2/p1, the best r1 is the maximum r1. So for each possible (p1, p2) we could compute ratio and then multiply by max r1? Wait but we need to pick r1 from its set. So for each (p1, p2) we would choose the maximum r1 available. So we can iterate over all pairs (p1, p2) (m * k up to maybe 2.5e7 if both 5000 => 25e6, borderline but maybe feasible? 25 million is okay in optimized C++ but Python might be heavy. Also n up to 5000, m,k up to 5000, product m*k = 25e6. If we then compute max r1 (which is constant) we can compute candidate r2 and keep max. However, we need to pick the maximum r1, but also r1 must be chosen from X. So indeed we just take max r1 overall, call Rmax = max(X). That is constant. Is that always optimal? Wait careful: The expression for r2 uses r1 linearly (multiplied by sqrt factor). So for any (p1,p2) the optimal r1 is the largest available. Because the factor sqrt(...) is independent of r1. So we would always choose the maximum r1 to maximize r2. That seems obvious: given any pair (p1, p2), r2 is proportional to r1. Since we are free to choose r1 from the set X, the best r1 is the maximum value in X. There's no constraint linking r1 to p1 or p2. So yes, we should always pick r1 = max(X). So the problem reduces to picking p1 in Y and p2 in Z to maximize f(p1,p2) = Rmax * sqrt( B p1 / (A p2 + B p1) ). So we just need to find the pair (p1, p2) that maximizes sqrt( B p1/(A p2 + B p1) ) or equivalently maximizes p1/(A p2 + B p1) since sqrt monotonic and B constant. Actually maximize B p1/(A p2 + B p1) = p1 / ( (A/B) p2 + p1 ) times constant? Let's do: f factor = sqrt( B p1/(A p2 + B p1) ). Since sqrt is monotonic, we can maximize g = B p1/(A p2 + B p1) = 1 / ( (A p2)/(B p1) + 1 ) = 1 / (1 + (A/B) * (p2/p1) ). So g is decreasing in (p2/p1). So to maximize g, we want to minimize p2/p1. That is, choose smallest ratio p2/p1 among all pairs (p1 from Y, p2 from Z). However, is that always sufficient? Since g is monotonic decreasing in ratio, yes. So the optimal pair is the one that minimizes p2/p1.
Thus the answer is: r2_max = Rmax * sqrt( B * p1_best / (A * p2_best + B * p1_best) ), where (p1_best, p2_best) is the pair from Y×Z that minimizes p2/p1.
But we must ensure p2/p1 ratio is minimized. Since Y and Z are sets of positive numbers, we can find the pair that gives smallest p2/p1. This is akin to finding min over p1 in Y, p2 in Z of p2/p1, which is equivalent to (min over Z) / (max over Y) ??? Let's see: p2/p1 minimized when p2 is as small as possible and p1 as large as possible, because p2 in numerator, p1 in denominator. So indeed the minimum ratio will be achieved by taking the smallest p2 and the largest p1. But is it always that simple? Consider Y = {100, 1}, Z = {1, 100}. min p2/p1: if we take p1=100, p2=1 => ratio=0.01; that's better than p1=1, p2=1 => ratio=1; also better than p1=100, p2=100 =>1; p1=1, p2=100 =>100. So indeed min ratio is min(p2)/max(p1) = 1/100 = 0.01. So the pair (max p1, min p2) yields the smallest ratio. However, is it possible that (max p1, min p2) might not exist? That is, we need to check if min p2 and max p1 are present; they are values from the sets. So yes, that pair yields ratio = min p2 / max p1. But could there be a pair with a slightly larger p1 but even smaller p2? p2 min is the global minimum, p1 max is the global maximum, so that ratio is the smallest possible. Because for any p1 <= max p1 and p2 >= min p2, we have p2/p1 >= min p2 / p1 >= min p2 / max p1? Wait careful: For any p1 ∈ Y, p2 ∈ Z: p2/p1 ≥ (min p2) / p1 ≥ (min p2) / max p1? Not exactly. Because (min p2)/p1 is less than or equal to (min p2)/max p1 if p1 >= max p1? Actually since p1 ≤ max p1, we have 1/p1 ≥ 1/max p1. So (min p2)/p1 ≥ (min p2)/max p1? Wait: if p1 ≤ max p1, then 1/p1 ≥ 1/max p1, so multiplying by min p2 (positive) gives (min p2)/p1 ≥ (min p2)/max p1. That means the ratio using min p2 with any p1 is at least min p2 / max p1. But that's only if we use min p2. However, using a p2 larger than min p2 can produce ratio larger than that. But could there be a pair with p2 not min but p1 larger than max? Not possible. So indeed the minimum ratio is min_{p1 in Y, p2 in Z} p2/p1 = min_{p2 in Z} p2 * min_{p1 in Y} (1/p1) ??? Actually min_{p1,p2} p2/p1 = (min_{p2} p2) * (min_{p1} 1/p1) = min p2 * (1 / max p1). Since 1/p1 is minimized when p1 is largest? Actually 1/p1 is smaller when p1 larger. The minimum of 1/p1 is 1/max p1. So product min p2 * (1/max p1) is the smallest possible. But careful: min over product of independent variables: min_{p2,p1} (p2 * (1/p1)) = (min p2) * (min over p1 of 1/p1). Yes, because p2 and 1/p1 are independent, we can take min for each. So indeed the minimum ratio is min p2 / max p1.
Thus the optimal pair is (p1 = max(Y), p2 = min(Z)). Provided that these sets are nonempty. And we also need to ensure that r2 is < r1 (but it will be automatically). So answer: r2 = Rmax * sqrt( B * p1_max / (A * p2_min + B * p1_max) ).
But wait, is there any twist? Check the second sample: max p1 = 2, min p2 = 6? Actually Z = {10,6,8}, min is 6. Yes that gives answer. So matches.
Thus the problem seems trivial: just compute max r1, max p1, min p2, and compute the formula. But why would they give large n,m,k up to maybe 5000 if solution is trivial? Maybe there is a nuance: The sets are not necessarily independent? Actually they are independent; jury can choose any combination. So indeed optimal choice is to take largest r1, largest p1, smallest p2. So answer is straightforward.
But before concluding, let's double-check the problem statement: "The jury wants to choose the value that would maximize radius r2." They need to choose r1, p1, p2 from given lists. That's all. There is no other constraint. So indeed the choice that maximizes r2 is independent: r1 larger always better, p1 larger always better, p2 smaller always better. So answer is simply based on extremes.
But maybe there is a catch: The ratio condition is m_out / m_in = A/B? But perhaps the ratio is something else? The problem statement says "ratio ... must equal ". In some problems, the image might depict a fraction like A/B. That's what we assumed. Could it be that the ratio is something like (A+B)/A or something? However, given examples, the ratio is A/B. In first example A=1, B=2 => ratio = 1/2. That's what we used. In second example A=2, B=1 => ratio = 2? Let's test: If ratio m_out/m_in = A/B = 2/1 = 2, then from our derivation we got r2 = r1 * sqrt( B p1 / (A p2 + B p1) ) = r1 * sqrt(1 * p1 / (2 p2 + 1 p1)). That matches. If ratio were B/A = 1/2, then expression would be different. So it's A/B.
Thus the formula is correct.
But wait: In first sample, p2 could be 3,2,1. min p2 = 1, max p1 = 2, max r1 = 3 -> answer matches. So trivial.
Thus the problem reduces to compute: Rmax = max(x_i), P1max = max(y_i), P2min = min(z_i). Compute r2 = Rmax * sqrt( (B * P1max) / (A * P2min + B * P1max) ).
But why did they provide sequences and possibly many numbers? Possibly to distract, but indeed the answer only depends on extremes. However, is there any scenario where using a non-extremal combination yields larger r2 due to the square root? Let's examine more thoroughly: r2 = r1 * sqrt( B p1 / (A p2 + B p1) ). For fixed r1, as p1 increases, the factor increases; as p2 increases, factor decreases. So each variable independently monotonic. So to maximize, we want r1 as large as possible, p1 as large as possible, p2 as small as possible. There's no interaction that would reverse this monotonicity. So yes, it's just extremes.
But hold on: There is a condition that the inner disk is inside the ring, meaning r2 < r1, but we already have that. Also r2 > 0. No other constraints.
Thus problem is trivial. But then why did they require error tolerance? Possibly because the answer is a real number that needs to be computed precisely with square root.
But wait: The input says "All numbers given in the input are positive and do not exceed 5000." The numbers are integers? They are integers, but the problem expects real output. That's fine.
Thus solution: parse input lines, get max of first list, max of second list, min of third list, then compute.
But before finalizing, read the problem carefully again:
"The World Programming Olympics Medal is a metal disk, consisting of two parts: the first part is a ring with outer radius of r1 cm, inner radius of r2 cm, (0 < r2 < r1) made of metal with density p1 g/cm3. The second part is an inner disk with radius r2 cm, it is made of metal with density p2 g/cm3. The disk is nested inside the ring.
The Olympic jury decided that r1 will take one of possible values of x1, x2, ..., xn. It is up to jury to decide which particular value r1 will take. Similarly, the Olympic jury decided that p1 will take one of possible value of y1, y2, ..., ym, and p2 will take a value from list z1, z2, ..., zk.
According to most ancient traditions the ratio between the outer ring mass mout and the inner disk mass min must equal , where A, B are constants taken from ancient books. Now, to start making medals, the jury needs to take values for r1, p1, p2 and calculate the suitable value of r2.
The jury wants to choose the value that would maximize radius r2. Help the jury find the sought value of r2. Value r2 doesn't have to be an integer.
Medal has a uniform thickness throughout the area, the thickness of the inner disk is the same as the thickness of the outer ring."
All clear.
Thus answer is as described.
But wait: Could there be a scenario where using the maximal r1 is not allowed because the ratio condition yields r2 >= r1? That would violate 0<r2<r1. But the problem says it's guaranteed that a solution meeting the requirements exists. It doesn't guarantee that for any combination it exists; but we must ensure that for the chosen combination, r2 < r1. Let's check: With our chosen max r1, max p1, min p2, we get r2 = r1 * sqrt( B p1 / (A p2 + B p1) ). Since sqrt factor <1, r2 < r1 automatically. So it's fine.
Thus solution is trivial.
But maybe there is a nuance: The ratio is m_out / m_in = A/B, but could it be m_in / m_out = A/B? No, the problem says "ratio between the outer ring mass mout and the inner disk mass min must equal ". So it's mout/min = something. So that's what we used.
Now check sample inputs: In second sample, A=2, B=1 => ratio = 2. So m_out/m_in = 2. That yields our formula.
Thus answer is correct.
Now confirm second sample manually: r1_max=6, p1_max=2, p2_min=6 => r2 = 6sqrt(21/(26+21)? Actually B=1, A=2 => factor sqrt(12/(26+1*2)= sqrt(2/(12+2)= sqrt(2/14)= sqrt(1/7)= ~0.377964473. Multiply by 6 => 2.26778684. Yes.
So trivial.
But before concluding, I should think: Could there be any hidden constraints like "the jury will decide r1, p1, p2 and then calculate suitable r2, but they must also ensure that r2 is positive and less than r1." Already satisfied.
Thus the solution is: read n and n numbers, find max; read m and m numbers, find max; read k and k numbers, find min; read A and B; compute result = max_r1 * sqrt( (B * max_p1) / (A * min_p2 + B * max_p1) ); print with sufficient precision.
But wait: In the input format, each line begins with the count and then the numbers. For example: "3 1 2 3" -> n=3, numbers: 1,2,3. That's fine. Similarly "1 2" -> m=1, numbers:2. Actually note: second line "1 2" meaning m=1, list contains only 2. So p1 only 2. Third line "3 3 2 1". So yes.
Thus simple.
But why would they need n,m,k up to maybe 5000? Possibly to prevent brute force if solution were more complex, but it's just extremes.
Thus I'll implement.
However, there is a possibility: The problem might be from an olympiad that expects participants to realize the monotonic property. So it's okay.
Double-check the formula derivation.
Mass outer: M_out = thickness * area_outer * density1. Area outer = π (r1^2 - r2^2). Mass inner: M_in = thickness * area_inner * density2. Area inner = π r2^2. Ratio: M_out / M_in = (p1 (r1^2 - r2^2)) / (p2 r2^2) = A/B. So:
p1 (r1^2 - r2^2) = (A/B) p2 r2^2? Actually cross multiply:
p1 (r1^2 - r2^2) / (p2 r2^2) = A/B
=> B p1 (r1^2 - r2^2) = A p2 r2^2
=> B p1 r1^2 - B p1 r2^2 = A p2 r2^2
=> B p1 r1^2 = r2^2 (A p2 + B p1)
=> r2^2 = (B p1 r1^2) / (A p2 + B p1)
=> r2 = r1 sqrt( B p1 / (A p2 + B p1) )
Yes.
Thus answer.
Now compute as double with high precision.
Edge cases: If A and B are large? All numbers <= 5000, so intermediate product B * p1 up to 5000*5000=25e6, A * p2 up to similar, sum up to 50e6, sqrt argument maybe <=1. So fine.
Now output with absolute or relative error 1e-6, so print with say 10-12 digits.
Thus code.
But is it always optimal to pick max p1 and min p2? Let's test with random numbers: Suppose p1 options: 100, 10; p2 options: 1, 1000. Then min p2=1, max p1=100 yields ratio p2/p1=0.01. So factor sqrt(B p1/(A p2+B p1)). For B=1, A=1: factor = sqrt(100/(1+100)) = sqrt(100/101) ≈ 0.995. Alternative: p1=10, p2=1 => ratio 0.1, factor = sqrt(10/11)≈0.953, less. p1=100, p2=1000 => ratio 10, factor sqrt(100/(1000+100))≈0.301. p1=10, p2=1000 => ratio 100, factor sqrt(10/(1000+10))≈0.0995. So indeed best is max p1, min p2.
Now consider scenario where p1 max and p2 min produce ratio not minimal? Wait p2 min / p1 max is the smallest possible ratio. Since the factor is decreasing in ratio, that's best.
Thus confirmed.
Now verify monotonic of factor with respect to p1 and p2 independently: For fixed p2, derivative of factor w.r.t p1? Let f(p1) = sqrt(B p1/(A p2+B p1)). Compute f^2 = B p1/(A p2+B p1) = 1 - (A p2)/(A p2+B p1). As p1 increases, denominator increases, so the subtracted term decreases, so f^2 increases, thus f increases. So monotonic increasing in p1. For fixed p1, as p2 increases, denominator increases, f decreases.
Thus independent.
So algorithm: read max_r1, max_p1, min_p2, compute answer.
But wait: In input, the numbers are integers but not necessarily sorted. So we need to parse correctly.
Implementation steps:
- Read entire line? Possibly there may be multiple lines? The format is: first line: n and then n integers. Second line: m and m integers. Third line: k and k integers. Fourth line: A and B.
Thus we can read using sys.stdin.read().split() to get all tokens.
Let tokens = list of strings from input.
First token: n (int). Then next n tokens: r1 values. Then next token: m. Then next m tokens: p1 values. Then next token: k. Then next k tokens: p2 values. Then two tokens: A, B.
Thus we can parse sequentially.
Compute max_r1 = max(r1_list) max_p1 = max(p1_list) min_p2 = min(p2_list)
Compute numerator = B * max_p1 denominator = A * min_p2 + B * max_p1 factor = math.sqrt(numerator / denominator) result = max_r1 * factor
Print result with appropriate precision: e.g., print("{:.12f}".format(result)) or just print(result) with enough digits? Use print with high precision.
But careful: The output example: "2.683281573000" has 12 decimal places. Probably print with 12 decimal places or more.
In Python, we can use print("{:.12f}".format(result)). However, note that the answer might require more digits? The error tolerance is 1e-6, so 12 decimal places is overkill but safe.
Now consider if there is any rounding issue? Should be fine.
Thus solution is trivial.
But before finalizing, let's think about potential pitfalls:
- The sets may contain only one element each, but that's fine.
- The numbers are up to 5000, but we are multiplying them, could be up to 25e6, still within double precision.
- The formula involves sqrt, okay.
Now double-check the condition: "r2 doesn't have to be an integer." So we output real.
But wait: Is there any scenario where using max r1 and max p1 and min p2 might violate 0<r2<r1? Already safe.
But what about the requirement 0 < r2 < r1. Could it be that the ratio condition yields r2 > r1 if some values are extreme? For instance, if p1 is huge relative to p2, the factor sqrt(B p1/(A p2 + B p1)) can approach 1 but never exceed 1. So r2 < r1 always. So fine.
Thus the problem seems too easy. Possibly there is a twist: The ratio between m_out and m_in must equal something like (A)/(B) but maybe the image shows something like A:B? However, the text: "ratio between the outer ring mass mout and the inner disk mass min must equal , where A, B are constants taken from ancient books." Usually could be a fraction A/B. So it's fine.
I'll re-read the original problem statement (since this is a textual copy). The placeholder might be something else, but given examples, it's consistent.
Now, perhaps the catch is that the medal thickness might be different? But they said "Medal has a uniform thickness throughout the area, the thickness of the inner disk is the same as the thickness of the outer ring." So same thickness, cancels.
Thus it's solved.
Nevertheless, I recall some problems where the ratio is given as A : B, meaning m_out : m_in = A : B, so m_out/m_in = A/B. Same.
Thus solution stands.
I'll write code accordingly.
But let's also consider the possibility that the ratio is m_out : m_in = A : B, but sometimes they might interpret ratio as (some fraction) but it's same.
Thus final answer.
But wait: Could there be any scenario where using the max r1 is not beneficial because the factor sqrt(...) depends on r1? Actually it doesn't. So yes, max r1 always best.
But what if the max r1 is extremely large, but the factor is very small due to p1 and p2 choices? Still, r2 = r1 * factor, so increasing r1 always increases r2 as long as factor >0. So always choose max r1.
Thus answer: use max r1, max p1, min p2.
One more nuance: The values are given as integers, but the answer is real.
Now test with some random values: Suppose X = {1, 1000}, Y = {1}, Z = {1000}, A=1, B=1. Then r2 = 1000 * sqrt(11/(11000+1*1)) = 1000 * sqrt(1/1001) ≈ 1000 * 0.0316 = 31.6. Alternative: using r1=1 with same p1,p2 gives 0.0316. So max r1 is best. So yes.
Thus implement.
But wait: The problem might have a twist: The jury chooses r1, p1, p2 and then calculates suitable r2 from the ratio equation. But the ratio equation involves r2; we solved for r2. However, note: r2 appears also in the definition of the ring inner radius. The ring's inner radius must equal the disk radius. That's fine. But does the equation have two solutions? For given r1, p1, p2, solving yields a unique positive r2 (since it's quadratic). So it's fine.
Now, guarantee that solution exists: for any combination? Possibly not all combinations yield positive r2 less than r1. But the problem says there exists a solution meeting requirements. It doesn't guarantee that every combination works. But we only need one that maximizes r2. Our chosen combination must yield a valid r2. Since r2 is positive and less than r1 as argued, it's valid.
But there is a subtlety: The equation we derived is for m_out/m_in = A/B. However, could it be that the ratio is reversed? Let's double-check sample 1: With our formula, we got r2=2.68328 for r1=3, p1=2, p2=1, A=1, B=2. Check if that yields m_out/m_in =? Compute masses (ignoring thickness and π): M_out = p1*(r1^2 - r2^2) = 2*(9 - 7.2 approx?) Actually r2^2 = 7.2 (since 2.68328^2 ≈ 7.200? Let's compute: 2.68328^2 ≈ 7.200 (since 2.683281573^2? Actually 2.683281573^2 =? In example output, likely r2^2 =? Let's compute: r2 = r1 * sqrt(B p1/(A p2+B p1)) = 3 * sqrt(22/(11+22)) = 3 * sqrt(4/5) = 3 * sqrt(0.8) = 3 * 0.894427191 = 2.683281573. So r2^2 = 7.2 exactly? 2.683281573^2 = 7.199999999? Actually sqrt(0.8) = sqrt(4/5). So r2 = 3 * sqrt(4/5) => r2^2 = 9 * 4/5 = 36/5 = 7.2 exactly. So M_out = 2(9 - 7.2) = 21.8=3.6; M_in = p2 * r2^2 = 17.2=7.2; ratio = 3.6/7.2=0.5 = 1/2. That's A/B=1/2. So correct.
Now, suppose the ratio was m_in/m_out = A/B, then we would have p2 r2^2 / (p1 (r1^2 - r2^2)) = A/B. That would yield r2^2 = (A p1 r1^2)/(A p1 + B p2). That would be different. Which one would produce the sample output? For sample1, r2 = r1 * sqrt( A p1 / (A p1 + B p2) )? = 3* sqrt(12/(12+21)) = 3 sqrt(2/4)=3* sqrt(0.5)=3*0.7071=2.1213, not matching. So that's not.
Thus ratio is m_out/m_in.
Thus final solution is simple.
But why would they ask to print r2 with high precision if it's just a simple formula? Possibly because they want to test if participants realize that the extremal values are the answer and not brute force.
Now code.
We'll parse input via sys.stdin.read().split() to handle any whitespace. Then convert to ints or later floats. Then compute.
Implementation steps in Python:
import sys, math
def main(): data = sys.stdin.read().strip().split() if not data: return it = iter(data) n = int(next(it)) r1_vals = [int(next(it)) for _ in range(n)] m = int(next(it)) p1_vals = [int(next(it)) for _ in range(m)] k = int(next(it)) p2_vals = [int(next(it)) for _ in range(k)] A = int(next(it)) B = int(next(it))
max_r1 = max(r1_vals) max_p1 = max(p1_vals) min_p2 = min(p2_vals) numerator = B * max_p1 denominator = A * min_p2 + B * max_p1 factor = math.sqrt(numerator / denominator) result = max_r1 * factor # print with enough precision print("{:.12f}".format(result))if name == "main": main()
That should work.
But wait: Are there any cases where p1_max and p2_min produce r2 that is not maximum? Let's try a contrived example: Suppose Y = {1, 1000}, Z = {1, 1000}. Then p1_max=1000, p2_min=1 gives ratio 0.001. r2 = r1 * sqrt(B1000/(A1+B*1000)). For A=1,B=1: sqrt(1000/1001) ≈ 0.9995. So near 1. Using p1=1000, p2=1 yields factor ~0.9995. Using p1=1, p2=1 gives factor sqrt(1/2)=0.7071. Using p1=1000, p2=1000 gives sqrt(1000/2000)=0.7071. Using p1=1, p2=1000 gives sqrt(1/1001)=0.0316. So max is indeed p1_max and p2_min.
Now consider Y = {1000, 2000} and Z = {500, 600}. p1_max=2000, p2_min=500 gives ratio 0.25. Suppose p1=1000, p2=500 gives ratio 0.5, factor smaller. So best is extremes.
Thus correct.
Now consider Y = {10, 20} and Z = {5, 15}. p1_max=20, p2_min=5 gives ratio 0.25. Suppose p1=10, p2=5 gives ratio 0.5, factor smaller. So yes.
Thus correct.
Thus answer.
Now, double-check reading: The third line includes k and then k numbers. In sample: "3 3 2 1" means k=3, numbers: 3,2,1. So min p2=1. That's fine.
But in code, we must ensure we correctly parse. Using iterator approach is fine.
Potential pitfalls: Input may have line breaks, but reading all tokens handles.
Now, is there any scenario where the optimal choice is not extremes due to requirement that r2 < r1? But that is satisfied.
What about the possibility that the ratio condition is not m_out/m_in = A/B but perhaps something like (m_out + m_in)/m_in = A/B? That would be different. But from examples, our interpretation fits.
Thus I'm confident.
However, I'll examine the problem statement once more to see if there is any hidden nuance:
"The ratio between the outer ring mass mout and the inner disk mass min must equal , where A, B are constants taken from ancient books."
Often, in such problems, the image could be a fraction, but sometimes it's a diagram like A/B? I think it's safe.
One might also consider that the thickness could be a factor if the inner disk and ring have different thicknesses, but they said same thickness.
Thus solution is trivial.
But wait: Could there be a twist that the jury chooses r1, p1, p2, but then they must also choose r2 based on those values such that the ratio condition holds, but r2 also must be positive and less than r1. For some combinations, the computed r2 might exceed r1 or be negative; but problem says guaranteed that solution exists (i.e., at least one combination yields valid). But if we choose extremes, might that combination be invalid? Let's check if any combination could yield r2 >= r1. That would require sqrt(B p1/(A p2 + B p1)) >= 1 => B p1 >= A p2 + B p1 => 0 >= A p2 => impossible since A,p2 positive. So r2 < r1 always. So all combinations produce valid r2 in the sense of 0<r2<r1. So extremes also produce valid r2.
Thus fine.
Now, there's one more nuance: The problem states: "The jury wants to choose the value that would maximize radius r2." But is r2 determined uniquely by r1,p1,p2 via ratio? Yes. So we are to pick combination.
Thus answer is as we described.
So why would they give multiple numbers? Maybe to trick participants into doing triple loops, but the problem is from a contest where participants would realize monotonicity.
Thus implement.
But before finalizing, let's see if there is any scenario where choosing a smaller r1 could be beneficial because with that r1 we could use a more favorable p1/p2 combination? However, p1 and p2 choices are independent of r1. So we can always use the best p1 and p2 regardless of r1. So we can always pair max r1 with best p1 and p2. So the best overall is max r1 with best p1/p2.
Thus answer.
So I'll produce final code.
One more: What if the lists contain only one element, but that element is not the extreme? That's fine.
Thus final answer.
But to be thorough, let's test with extreme values: Suppose X = {5, 10}, Y = {1, 1000}, Z = {1, 1000}, A=5000, B=1. Then p1_max=1000, p2_min=1. Then factor = sqrt(11000/(50001 + 11000)) = sqrt(1000/6000) = sqrt(1/6) ≈0.4082. r2 = 10 * 0.4082 = 4.082. If we used p1=1000, p2=1000, factor = sqrt(1000/(5000+1000)) = sqrt(1000/6000) same? Actually A p2 = 50001000 = 5,000,000, B p1 = 1000, denominator = 5,001,000, factor ≈ sqrt(1000/5,001,000) = sqrt(0.00019996) ≈ 0.01414, much smaller. So extremes best.
What about using p1=1, p2=1: factor = sqrt(1/(5000+1)) ≈ 0.0141, then r2 for r1=10 gives 0.141, smaller. So yes.
Now consider if A or B can be zero? Input says positive numbers. So >0.
Thus solution is trivial.
Nevertheless, one might ask: Could there be a scenario where the maximum r1 is very large, but the maximum p1 is very small compared to other p1's? Actually maximum p1 is the largest, so it's best.
Thus final.
I'll write solution in Python.
But wait: The input numbers are up to 5000, but n,m,k could be up to maybe 5000 each, so reading and computing max/min is O(n+m+k). Fine.
Thus code.
Now, I'll also consider alternative solution: We could have used triple loop if n,m,k small, but they can be up to 5000, so O(nmk) is impossible.
Thus it's important to use monotonic property.
Thus answer is final.
Now produce final response. ```python
import sys import math
def main(): data = sys.stdin.read().strip().split() if not data: return it = iter(data)
# first line: n and r1 values n = int(next(it)) r1_vals = [int(next(it)) for _ in range(n)] # second line: m and p1 values m = int(next(it)) p1_vals = [int(next(it)) for _ in range(m)] # third line: k and p2 values k = int(next(it)) p2_vals = [int(next(it)) for _ in range(k)] # fourth line: A and B A = int(next(it)) B = int(next(it)) # optimal choices: largest r1, largest p1, smallest p2 max_r1 = max(r1_vals) max_p1 = max(p1_vals) min_p2 = min(p2_vals) # r2 = max_r1 * sqrt( B * max_p1 / (A * min_p2 + B * max_p1) ) numerator = B * max_p1 denominator = A * min_p2 + B * max_p1 factor = math.sqrt(numerator / denominator) result = max_r1 * factor # output with sufficient precision print("{:.12f}".format(result))if name == "main": main()