Pogo-Cow
Time limit1sMemory limit128 MB
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 targets at distinct positions on the path for Bessie to land on (). Target sits at position and is worth 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 . The -th of the next lines has the position and the value of target , both integers in the range to . All target positions are distinct.
Output
Print the largest number of points Bessie can collect.
Hint
In the sample Bessie starts at position and hops to position , then position , then position . The hop lengths , , never shrink, and the score is .