Ski Lessons
Time limit1sMemory limit128 MB
Given ski lessons that overwrite Bessie's skill at fixed start times and slopes with skill and time costs, maximize the number of runs by time T.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Greedy, Sorting, Binary search
- Solved
- No attempts yet
Problem
Farmer John wants to take Bessie skiing in Colorado. Sadly, Bessie is not a very good skier.
The ski resort offers ski lessons throughout the day (). Lesson starts at time and lasts for units of time (, ). When lesson finishes (i.e. at time ), Bessie's skill level becomes (). This is an absolute value that overwrites her skill, not an increment.
The resort has ski slopes (). Skiing down slope once takes units of time () and requires a skill level of at least to descend safely (). Bessie may descend slope only when her skill level is at least . She may ski any slope as many times as she likes, and each descent counts as one run.
Bessie can spend her time skiing, taking lessons, or resting (sipping hot cocoa), but she can only do one thing at a time. A lesson starts at its fixed time , so to attend it she must be free (not in the middle of a descent or another lesson) at exactly time .
Bessie starts the day at time with skill level and must leave the resort by time (); that is, she must complete the descent of her last slope without exceeding time .
Find the maximum number of runs Bessie can complete within the time limit.
Input
- Line 1: three space-separated integers , , and
- Next lines: line describes lesson with three space-separated integers , , and
- Next lines: line describes slope with two space-separated integers and
Output
Print a single integer on its own line: the maximum number of runs Bessie can complete within the time limit.
Hint
One optimal strategy is: ski the slope with , once (time ), take the lesson that starts at time to raise the skill level to (time ), then ski the slope with , five times before time runs out (time ), for a total of runs.