Gather at one point
Time limit5sMemory limit512 MB
For each query [l, r], find the minimum sum of Chebyshev distances from the people l..r to a freely chosen point.
- Level
Medium7 of 10
- Topics
- Prefix sum, Divide and conquer, Math, Sorting
- Solved
- No attempts yet
Problem
people stand on a two dimensional plane. The people are numbered from 1 to .
The distance between two points and is .
Write a program that answers the following query.
l r: person through person gather at a single point on the plane. Print the minimum possible sum of the distances between each of those people and .
The point can be anywhere on the plane, and its coordinates do not have to be integers.
Input
The first line contains the number of people and the number of queries , separated by a space. ()
Each of the next lines contains the coordinates and of person , separated by a space. ()
Each of the next lines contains and of a query, separated by a space. ()
Output
Print the answer to each query on its own line, in the order the queries are given.
The answer is always a multiple of , so print it with exactly one digit after the decimal point. Print 5.0 for an answer of and 8.5 for an answer of .
Hint
In the first example, the first query is minimized by gathering at , and the second query is minimized by gathering at .