Hanyang Popularity Exceeding Competition
Time limit1sMemory limit1024 MB
Pick a subsequence of celebrities to meet in order, where each meeting adds 1 only if |P-X| is at most C. Find the maximum final popularity.
- Level
Medium5 of 10
- Topics
- Dynamic programming, Array
- Solved
- No attempts yet
Problem
Hanyang University has held the Hanyang Popularity Exceeding Competition since 2023. The contest runs for a set period, and the student with the highest popularity when it ends wins. Cheolmin is a contestant, but he has just started school, so his popularity is .
Cheolmin made a plan to win by meeting celebrities of Hanyang University. He will meet them in order, from celebrity 1 to celebrity .
Real life is more complicated. Meeting a celebrity does not always raise popularity. If one side's fame is far higher than the other's, the higher side drowns out the other. Precisely, let Cheolmin's current popularity be , celebrity 's popularity , and affinity . If , Cheolmin's popularity increases by . If , his popularity does not change.
Instead of meeting all celebrities, Cheolmin picks some of them to meet and tries to maximize his popularity. What is the maximum popularity Cheolmin can reach?
The celebrities are busy, so the meeting times cannot be changed. In other words, Cheolmin cannot change the plan to meet a higher-numbered celebrity first.
Input
The first line contains , the number of celebrities at Hanyang University. ()
Each of the next lines contains two integers and , the popularity and affinity of celebrity , separated by a space. ()
Output
Print the maximum popularity Cheolmin can reach on the first line.