Highways
Practice
3.1 (8 votes)
Binary search
Implementation
Algorithms
Pointer
Problem
84% Success 978 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Some country X is a square of \(N\times N\) cells. Its inhabitants use a coordinate system in which the lower-left and upper-right corners of the square have coordinates $$(0, 0)$$ and $$(N, N)$$. There are $$K$$ cities in the country, each at a point with integer coordinates.

Residents of country X move around the country parallel to the coordinate axes. To speed up travel to neighboring countries, the government has decided to build two highways. Highways must be perpendicular to each other and parallel to the coordinate axes. Each trunk will connect two opposite sides of the square.
The distance from the city to the highways will be the distance from the city to the nearest one. The government has decided to place highways so that the maximum distance from cities to highways is the minimum possible.
Your task is to find the optimal distance from the farthest city to the nearest highway.

Input format

  • The first line contains two numbers $$N$$ and $$K$$ denoting the length of the side of the square and the number of cities respectively.
  • The next $$K$$ lines contain two numbers denoting the coordinates of cities (from 0 to N).

Output format

Print the answer to the problem.

Constraints

\(1 \le N \le 10^6\\ 1 \le K \le 4\times 10^4\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
2 votes
Tags:
OpenDynamic ProgrammingAlgorithmsExpectationApprovedMedium
Points:30
14 votes
Tags:
AlgorithmsBinary SearchMediumSearching
Points:30
8 votes
Tags:
AlgorithmsBinary SearchHiringImplementationMediumSearchingString Manipulation