Similar statements (5) P12471


Statement
 

pdf   zip

Consider two infinite horizontal lines AA and BB, separated \ell units apart. The line AA has mm points at the abscissae a1,,ama_1, \dots, a_m. The line BB has nn points at the abscissae b1,,bnb_1, \dots, b_n. Given pp different indices i1,,ipi_1, \dots, i_p choosen from {1m}\{1 \dots m\}, and pp different indices j1,,jpj_1, \dots, j_p choosen from {1n}\{1 \dots n\}, define dkd_k as the Euclidean distance between aika_{i_k} and bjkb_{j_k}, that is, dk=(aikbjk)2+2.d_k = \sqrt{(a_{i_k} - b_{j_k})^2 + \ell^2} \enspace .

You are given \ell, pp, and the points in AA and in BB. Pick i1,,ipi_1, \dots, i_p and j1,,jpj_1, \dots, j_p in order to

minimize maxk=1..pdk\max_{k=1..p} \enspace d_k

Input

Input consists of several cases, each one with only integer numbers. Every case begins with four strictly positive numbers \ell, pp, mm and nn. Follow a1a2am1ama_1 \le a_2 \le \dots \le a_{m-1} \le a_m. Follow b1b2bn1bnb_1 \le b_2 \le \dots \le b_{n-1} \le b_n. Assume 106\ell \le 10^6, pmin(m,n)p \le \min(m, n), and that the absolute value of each abscissa is at most 10610^6.

Additionally, assume that mm and nn are at most 10410^4.

Output

For every case, print the result with four digits after the decimal point. If you use the long double type, the input cases have no precision issues.

Public test cases
  • Input

    1 1 2 2
    5 10
    9 20
    
    1 2 2 2
    5 10
    9 20
    
    1000000 4 5 4
    300000 300000 300000 300000 300000
    -500000 -500000 -500000 -500000
    
    3 2 7 4
    0 2 4 6 8 10 12
    1 4 7 10
    

    Output

    1.4142
    10.0499
    1280624.8475
    3.0000
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Other languages
    Spanish
    Official solutions
    C++
    User solutions
    C++