Apprentice Learning Trajectory
Time limit3sMemory limit512 MB
Given n masters, each with a work window [a_i, b_i] and a sword time t_i, find the most non-overlapping sword segments, each of length t_i inside one window.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Intervals, Greedy
- Solved
- No attempts yet
Problem
Abigail is an apprentice studying to become a blacksmith. She wants to plan her learning trajectory and make as many swords as possible on her way to becoming a famous expert.
There are masters willing to host her as their apprentice. The -th master starts working at minute and stops at minute , so the master works for minutes in total. During this interval, Abigail can work at this master's forge. She can enter and leave the forge several times and produce one or several swords upon each arrival. To produce a sword under the -th master's supervision, she must work there for minutes in a row. She cannot leave a sword unfinished and continue it on her next visit to the same forge.
Help Abigail make an optimal plan and calculate the maximum number of swords she can produce under the supervision of the masters.
Input
The first line contains an integer (), the number of masters.
Each of the next lines contains three integers , , and (), the start time, end time, and the time needed to make one sword at the -th master's forge.
Output
Output the maximum number of swords Abigail can produce using an optimal learning trajectory.