Neutral Spectator

시간 제한2초메모리 제한2048 MB

요약
길이 x와 y인 연속 구간을 각각 골랐을 때 모든 교차 쌍의 (공격 합)/(방어 합) 비율의 최솟값을 최대화하는 값을 각 질의마다 구한다.
난이도

어려움10점 중 8점

유형
이분 탐색, 정렬, 분할 정복, 기하
정답자
아직 제출이 없습니다

문제

The battle of the mages continues! Today Svetozar has gathered a team of nn good mages, while Arglwyddytywyllwch has assembled a team of mm evil mages.

Each mage has the ability to attack by casting spells and the ability to defend against the spells of other mages, expressed as certain numbers. The outcome of the battle and its spectacle depend on these abilities. The ii-th good mage has the attack ability a_ia\_i and the defense ability b_ib\_i; the ii-th evil mage has the attack ability c_ic\_i and the defense ability d_id\_i.

Before the battle begins, Svetozar and Arglwyddytywyllwch will choose several consecutive mages from their teams (that is, if LL-th and RR-th mages are chosen in a team, then mages L+1,L+2,…,R−1L + 1, L + 2, \ldots, R - 1 from the same team are also chosen). Only the chosen mages from each team will fight.

You are an unbiased, neutral spectator, and you are not very concerned about which side will win. You are more interested in the spectacle. You will be dissatisfied if at least one pair of mages from different teams does not fight intensely enough. You define the intensity f(i,j)f(i, j) of the battle between the ii-th good mage and the jj-th evil mage as the ratio of the sum of their attack abilities to the sum of their defense abilities, that is, f(i,j)=a_i+c_jb_i+d_j.f(i, j) = \dfrac{a\_i + c\_j}{b\_i + d\_j}.

You define the intensity of the entire battle between the good mages with indices from pp to qq (p≤qp \leq q) and the evil mages with indices from rr to ss (r≤sr \leq s) as the minimum intensity of the battle among all pairs of chosen mages from different teams, that is, as

min⁡_i=pqmin⁡_j=rsf(i,j).\min\limits\_{i = p}^{q}\min\limits\_{j = r}^{s} f(i, j).

Before the battle begins, you have considered qq hypothetical situations: given that exactly xx good mages and exactly yy evil mages will be chosen, what is the maximum possible intensity of the upcoming battle?

입력

The first line contains a single integer TT (1≤T≤1051 \leq T \leq 10^5), denoting the number of test cases.

Then TT descriptions of test cases follow. The first line of each description contains three integers nn, mm, qq (1≤n,m,q≤1051 \leq n, m, q \leq 10^5): the number of mages in Svetozar's team, the number of mages in Arglwyddytywyllwch's team, and the number of hypothetical situations.

The second line contains nn integers a_1,…,a_na\_1, \ldots, a\_n: the abilities of the good mages to attack.

The third line contains nn integers b_1,…,b_nb\_1, \ldots, b\_n: the abilities of the good mages to defend.

The fourth line contains mm integers c_1,…,c_mc\_1, \ldots, c\_m: the abilities of the evil mages to attack.

The fifth line contains mm integers d_1,…,d_md\_1, \ldots, d\_m: the abilities of the evil mages to defend.

Each of the following qq lines contains two integers xx and yy (1≤x≤n1 \leq x \leq n, 1≤y≤m1 \leq y \leq m): the number of chosen good mages and the number of chosen evil mages in a hypothetical situation.

It is guaranteed that 1≤a_i,b_i,c_j,d_j≤10001 \leq a\_i, b\_i, c\_j, d\_j \leq 1000 for 1≤i≤n1 \leq i \leq n, 1≤j≤m1 \leq j \leq m. It is also guaranteed that the sum of all values (n+m)⋅q(n + m) \cdot q over all test cases does not exceed 2⋅1052 \cdot 10^5.

출력

For each test case, output qq lines. Each line should contain a single real number: maximum possible intensity of the corresponding battle. The answer will be considered correct if its absolute or relative error does not exceed 10−610^{-6}.

힌트

The intensities of battles between the good mages and each of the evil mages in the first test case are:

for the first good mage: 11, 11, 11, 11;

for the second good mage: 78\frac{7}{8}, 89\frac{8}{9}, 910\frac{9}{10}, 1011\frac{10}{11};

for the third good mage: 79\frac{7}{9}, 45\frac{4}{5}, 911\frac{9}{11}, 56\frac{5}{6}.

In the second test case, there are only two mages, and the intensity of their battle is 1000+11+1000=1\frac{1000 + 1}{1 + 1000} = 1.

예제1

  1. 예제 1

    입력
    2
    3 4 5
    1 1 1
    2 3 4
    6 7 8 9
    5 6 7 8
    1 1
    1 2
    2 1
    3 3
    3 4
    1 1 1
    1000
    1
    1
    1000
    1 1
    
    예상 출력
    1.000000000
    1.000000000
    0.909090909
    0.800000000
    0.777777778
    1.000000000