This page is still under construction.

Parts of this page are still being built. What you see may change.

Pogo-Cow

Time limit1sMemory limit128 MB

Summary
Starting from any target and hopping in one direction with non-decreasing jump lengths, collect the maximum total points from visited targets.
Level

Medium7 of 10

Topics
Dynamic programming, Sorting
Solved
No attempts yet

Problem

Farmer John wanted his prize cow Bessie to get around faster, so he attached a pogo stick to each of her legs. It was not a good idea. Bessie now hops across the farm quickly, but she has not learned how to slow down.

To train Bessie to control her hops, Farmer John built a practice course along a straight path across the farm. He placed NN targets at distinct positions on the path for Bessie to land on (1≤N≤1 0001 \le N \le 1\,000). Target ii sits at position xix_i and is worth pip_i points when Bessie lands on it.

Bessie picks any one target to start on and then moves in a single direction, hopping from target to target. No hop may be shorter than the hop before it, and every hop has to land on a target. The first hop has no length restriction.

Every target Bessie touches scores, including the one she starts on. Find the largest number of points she can collect.

Input

The first line has the number of targets NN. The ii-th of the next NN lines has the position xix_i and the value pip_i of target ii, both integers in the range 00 to 1 000 0001\,000\,000. All target positions are distinct.

Output

Print the largest number of points Bessie can collect.

Hint

In the sample Bessie starts at position 44 and hops to position 55, then position 77, then position 1010. The hop lengths 11, 22, 33 never shrink, and the score is 8+6+6+5=258 + 6 + 6 + 5 = 25.

Examples1

  1. Example 1

    Input
    6
    5 6
    1 1
    10 5
    7 6
    4 8
    8 10
    
    Expected output
    25