Training, Round 2
Time limit6sMemory limit2048 MB
Given n problems with implementation and thinking skill ranges, find the most problems Ashley can solve in order when each solve raises one of her skills by one.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Intervals, Bit manipulation
- Solved
- No attempts yet
Problem
Ashley is training for another programming contest on Brandon's Online Judge. The judge still lets Ashley's coach, Tom, load a list of problems for Ashley to work on.
Tom has curated some problems. Each problem has an implementation difficulty range and a thinking difficulty range. Ashley starts with an implementation skill and a thinking skill . She looks at the problems in the order Tom loaded them, and for each one she either solves it or skips it. Once she skips a problem, she cannot go back to it.
Ashley can solve a problem only if both her current implementation skill and her current thinking skill are inside that problem's ranges, endpoints included. After each solved problem, she reflects and raises either her implementation skill or her thinking skill by one. She cannot raise both at once, and she cannot skip the reflection.
Find the maximum number of problems Ashley can solve if she chooses her reflections optimally.
Input
The first line contains three integers , , and (, ), where is the number of problems, is Ashley's starting implementation skill, and is her starting thinking skill.
Each of the next lines contains four integers , , , and (, ). Each line describes one problem. Its implementation range is and its thinking range is , both inclusive.
Output
Print one integer, the maximum number of problems Ashley can solve when she chooses her reflections optimally.