Processing math: 100%
Wooden sticks - MarisaOJ: Marisa Online Judge

Wooden sticks

Time limit: 1000 ms
Memory limit: 256 MB
Given n sticks. The ith stick has a length of ai, and there is a marked point on the stick located bi from one end (and ai−bi from the other end). You need to arrange the n sticks parallel to each other such that there exists a straight line passing through all the marked points on the sticks, and this line is perpendicular to the sticks. Determine the maximum length that all the sticks can collectively cover. **You can rotate the stick freely.** For example, with two sticks (5,2) and (4,1), the maximum horizontal length they can cover is 6.
### Input - The first line contains an integer n. - The next n lines each contain two integers ai and bi. ### Output - Print a single integer, the maximum length that can be covered. ### Constraints - 1≤n≤105. - 1≤ai,bi≤109. ### Example Input: 25243 Output: 6 Input 2: 454535251 Output 2: 8 ### Subtasks - Subtask 1 (20 of the points): 1≤n,ai,bi≤10. - Subtask 2 (20 of the points): 1≤n≤2. - Subtask 3 (20 of the points): 1≤n≤1000. - Subtask 4 (20 of the points): bi=0 for all 1≤i≤n. - Subtask 5 (20 of the points): No additional constraints.