UberOA #60
Find Point Illuminated by Most Lamps
Estimated MediumJudge-ready
Topics (AI-labelled)Prefix & Ranges
A lamp (x,r) lights the closed interval [x−r,x+r], with r>0. Return the position lit by the most lamps at once; if several positions tie, take the smallest coordinate.
This site has made the standard input and output explicit.
Input
The first line contains n, followed by n lines of x r. On this site 1≤n≤200000, −10⁹≤x≤10⁹, 1≤r≤10⁹.
Output
Output one integer, the answer.
Example 1
Input:
3
-2 3
2 3
2 1
Output:
1
Example 2
Input:
2
-2 1
2 1
Output:
-3
Example 3
Input:
2
0 1
2 1
Output:
1
Example notes
Example 1: the only position shared by all three lamps is 1. Example 2: at most one lamp lights any position, and the leftmost such position is −3. Example 3: the two segments meet at the closed endpoint 1, which is lit by both lamps, so the answer is 1.
Editorial
Loading solution…