Complex Simulation_Special Trains
AtCoder Nation has newly built a railway, running east-west, with a total of
N
N stations along the line, numbered from west to east as
1
,
2
,
⋯
,
N
1,2,⋯,N
Tomorrow the railway will hold its opening ceremony. All trains run from west to east, and trains only operate between adjacent stations. A train from station
i
i to station
i
+
1
i+1 takes
C
i
C
i
seconds for the entire trip.
The first train departing from station
i
i to station
i
+
1
i+1 departs
S
i
S
i
seconds after the opening ceremony begins, and thereafter a train departs every
F
i
F
i
seconds (it is guaranteed that
S
i
S
i
is always a multiple of
F
i
F
i
).
Ignoring transfer time, please calculate, for a passenger departing from station
i
i, the earliest possible time, in seconds after the opening ceremony begins, at which they can arrive at the final station
N
N.
Input Description
The first line contains a positive integer
N
N
The following
N
−
1
N−1 lines each contain three positive integers
C
i
,
S
i
,
F
i
C
i
,S
i
,F
i
Output Description
Output
N
N lines, where the
i
i-th line outputs the earliest time for a passenger departing from station
i
i to arrive at station
N
N.
← Back to blog
Comments(0)
No comments yet — say the first word