Ostap and chairs
Time limit1sMemory limit256 MB
Given N x-coordinates and N y-coordinates, find real k and b minimizing the sum of |x_i - (k*y_i + b)|.
- Level
Hard8 of 10
- Topics
- Geometry, Binary search, Greedy, Math
- Solved
- No attempts yet
Problem
There is an emotional moment in the computer game called <>, when each Ostap, from a crowd of tiny Ostaps, runs to his own chair. The graphics of the event has been drawn already: the first image is of Ostaps (with predefined coordinates ), and the second image is of the chairs (their coordinates are also known).
Before you start a game, you cannot move Ostaps or chairs, but you can change the scale of the second picture using a linear transformation . After that, the first Ostap runs to the first chair, then the second Ostap runs to the second chair, etc., and the total elapsed time is summed up. The player's task is to make this time as short as possible, i.e. minimize the total summarized distance.
Your task is to find the minimum possible value:
Input
The first line of the input file contains a single integer , the number of Ostaps and chairs (). Each of the following two lines contains integers: the second line of the file contains , the coordinates of Ostaps, the third line contains , the coordinates of chairs (, ). All are different, all are different.
Output
In your answer, print three real numbers: , the minimum possible value of the total distance, and and , coefficients with which such distance is achievable.
The relative or absolute deviation of the distance from the optimal must not exceed . The total distance calculated using the coefficients and must match with the same precision.