Location, Location, Location
InterviewTime limit3sMemory limit1024 MB
Given n integer points, find the point that minimizes the total Manhattan distance to all of them, breaking ties by smallest x, then smallest y.
Problem
The phrase location, location, location is common in real estate and business. It stresses that the physical location of a property or business matters. In real estate, a property's desirability and value depend heavily on its location, often more than on its features or condition. In business, the success of a retail store or commercial establishment can be strongly affected by where it is.
Recently, more people are buying electric vehicles, but buyers soon find it hard to install charging piles at their apartments or houses. A charging station can earn a lot of money. Your boss, Lena, asks you to find a good place to build a charging station for electric vehicle owners.
Input
You are given locations as coordinates on a 2D plane. Each location has an apartment or house without charging infrastructure. Your task is to build a charging station at the location that is closest to all locations in the list. Distance is measured with Manhattan distance. The Manhattan distance between two points and is . Find a location that minimizes the sum of Manhattan distances from to all locations.
Output
Print the location that minimizes the sum of Manhattan distances from to all locations. If there are multiple solutions, print the one with the smallest . If there are still multiple solutions, print the one with the smallest .
Constraints
, for , and for .