#P1882. 接力赛跑
接力赛跑
Description
There are cows (numbered from to ) participating in a special relay race, where multiple cows are allowed to run simultaneously.
At time , cow starts running along the track.
Normally, cow needs seconds to complete one lap. At the instant it crosses the start line again, it will notify cows to start. Note that it is possible that and the list does not exist.
Every cow that starts racing will, upon returning to the start line, notify other cows to start. It is possible that multiple cows notify the same cow to start, but each cow is willing to run only one lap, so any cow starts at most once.
The farmer wants you to determine the total race time (that is, from the race start to the moment when the last cow crosses the finish line).
Input Format
The first line contains an integer , the number of participating cows.
Lines to : line contains multiple space-separated integers: , , and integers .
Output Format
Output a single integer, the time when the entire race ends.
5
4 2 2 4
3 3 1 3 4
7 1 5
4 2 3 5
1 0
14
Hint
Translated by ChatGPT 5
京公网安备 11011102002149号