Training
InterviewTime limit1sMemory limit2048 MB
Given problems with skill ranges [l, r] in a fixed order, choose which to solve so the final skill level is maximized, where a solve needs the current skill inside the range.
- Level
Medium4 of 10
- Topics
- Greedy, Simulation
- Solved
- No attempts yet
Problem
Ashley is training for a programming contest on Brandon's Online Judge. The judge has a new feature that lets Ashley's coach, Tom, load a list of problems for her.
Each problem has two integers, a lower skill bound and an upper skill bound . Each programmer has an integer skill level. If a programmer whose skill level is between and (inclusive) solves the problem, their skill level goes up by .
Ashley trains on Tom's list in the order Tom loaded the problems. For each problem, she either solves it or skips it. Once she skips a problem, she cannot go back to it.
Compute the maximum skill level Ashley can have if she chooses to solve or skip problems optimally.
Input
The first line contains two integers and (, ), where is the number of problems and is Ashley's current skill level.
Each of the next lines contains two integers and (), the lower and upper skill bounds of a problem, in the order Tom loaded them.
Output
Output a single integer, the maximum skill level Ashley can attain.