Best Fishing Spot

View as PDF

Submit solution

Points: 7
Time limit: 1.0s
C++14 0.5s
Memory limit: 64M

Author:
Problem types
Allowed languages
C++, Java, JS, Python

There are n fish swimming back and forth on an integer number line. The movements of each fish f_1, f_2, ..., f_n can be described by a pair of integers f_i = (h_i, r_i) where h_i represents that fish's home and r_i represents the number of units in each direction from their home that they will reach by swimming. For example, if a fish is described by (-1, 5) then they live at -1 and reach anywhere in [-6, 4] on the number line.

We are interested in finding the optimal spot on the number line to fish. This is the spot such that the number of fish that can reach it is maximized.

Input Specification

The first line contains n
The next n lines contains two space separated integers, h_i and r_i.
1 \le n \le 10^5
-10^9 \le h_i \le 10^9
-10^4 \le r_i \le 10^4

Output Specification

Output a single integer: the spot on the number that is reached by the most fish. If there are multiple such spots, output the lowest one.

Example

Suppose the following input:

3
-5 3
0 4
0 3

The expected output is:

-3

Reasoning: The first fish can reach [-8, -2], the second can reach [-4, 4], and the third reaches [-3, 3]. All three fishes can reach points -3 and -2, so we output the smaller number -3.


Comments

There are no comments at the moment.