#P12934. [NERC 2019] Apprentice Learning Trajectory

[NERC 2019] Apprentice Learning Trajectory

题目描述

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 nn masters willing to host her as their apprentice. The ii-th master will start working at the minute aia_i and end working at the minute bib_i, working for a total of biaib_i - a_i minutes. During this interval of time, 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. However, in order to produce a sword under supervision of the ii-th master she has to work there for tit_i minutes in a row. She can't leave the sword unfinished and continue working on it upon her next arrival to this forge.

Help Abigail make an optimal plan and calculate the maximum number of swords she can produce under the supervision of nn masters.

输入格式

The first line contains integer nn (1n2000001 \le n \le 200\,000) --- the number of masters.

Each of the next nn lines contains three integers ai,bi,tia_i, b_i, t_i (1ai<ai+tibi10181 \le a_i < a_i + t_i \le b_i \le 10^{18}) --- the start and the end time of master's work, and the time needed to make one sword in their forge.

输出格式

Output the maximum number of swords Abigail can produce using the optimal learning trajectory.

2
5 7 1
1 9 2
5
3
1 10 4
6 12 3
9 13 2
4
3
1 13 4
6 11 2
9 13 3
4

提示