Under construction

Still being built. Things may change

B Road Band

Time limit4sMemory limit1024 MB

Summary
Place k access points on a midline to minimize the sum of squared distances from customers on two parallel streets to their nearest access point.
Level

Medium6 of 10

Topics
Dynamic programming, Sorting, Prefix sum
Solved
No attempts yet

Problem

All the residents of the rural community of Axes Point live on one of two parallel streets separated by a band of green park land. Recently, the local board of supervisors received a grant to bring wireless service to the town. The grant pays for kk access points, and the supervisors have decided to place them in a straight line on County Road "B," which lies in the wooded band midway between the two residential streets. They want to place them so that the distance between each user and the nearest access point is as small as possible. Specifically, they want to minimize the sum of the squares of the distances of each user from the nearest access point.

The figure shows two streets with eight customers and their locations along the streets. The streets are 33 units apart, and two access points are placed at points midway between the two streets so that the sum of the eight squared distances is minimized.

Given the locations of all customers along each street, the distance between the streets, and the number of access points, find the minimum sum of squared distances that can be achieved.

Input

The first line contains four integers mm, nn, kk, ss. Here mm and nn (1≤m,n≤10001 \leq m,n \leq 1000) are the numbers of customers along each of the two roads, kk (1≤k≤min⁡(max⁡(m,n),100)1 \leq k \leq \min(\max(m,n),100)) is the number of access points, and ss (1≤s≤501 \leq s \leq 50) is the distance between the two roads.

The second line contains mm floating-point values x1,x2,…,xmx_1, x_2, \ldots, x_m (0≤xi≤10000 \leq x_i \leq 1000), the locations of the customers along the first road. The third line contains nn floating-point locations of the customers along the second road. All values on each of the second and third lines are distinct, but some values may appear on both lines. Customer locations have no more than four decimal places.

Output

Output a single floating-point value equal to the minimum sum of squared distances from each customer to the closest of the kk access points. An answer is accepted if its absolute or relative error is at most 10−510^{-5}.

Examples1

  1. Example 1

    Input
    4 4 2 3
    0.5 1.0 3.0 3.5
    1.0 2.5 3.0 3.5
    
    Expected output
    18.86666667