Problem:


Score : 300 points

Problem Statement

A railroad running from west to east in Atcoder Kingdom is now complete.

There are N stations on the railroad, numbered 1 through N from west to east.

Tomorrow, the opening ceremony of the railroad will take place.

On this railroad, for each integer i such that 1≤i≤N-1, there will be trains that run from Station i to Station i+1 in C_i seconds. No other trains will be operated.

The first train from Station i to Station i+1 will depart Station i S_i seconds after the ceremony begins. Thereafter, there will be a train that departs Station i every F_i seconds.

Here, it is guaranteed that F_i divides S_i.

That is, for each Time t satisfying S_i≤t and t％F_i=0, there will be a train that departs Station i t seconds after the ceremony begins and arrives at Station i+1 t+C_i seconds after the ceremony begins, where A％B denotes A modulo B, and there will be no other trains.

For each i, find the earliest possible time we can reach Station N if we are at Station i when the ceremony begins, ignoring the time needed to change trains.

Constraints

1≤N≤500

1≤C_i≤100

1≤S_i≤10^5

1≤F_i≤10

S_i％F_i=0

All input values are integers.

Input

Input is given from Standard Input in the following format:

N
C_1 S_1 F_1
:
C_{N-1} S_{N-1} F_{N-1}

Output

Print N lines. Assuming that we are at Station i (1≤i≤N) when the ceremony begins, if the earliest possible time we can reach Station N is x seconds after the ceremony begins, the i-th line should contain x.

Sample Input 1

3
6 5 1
1 10 1

Sample Output 1

12
11
0

We will travel from Station 1 as follows:

5 seconds after the beginning: take the train to Station 2.

11 seconds: arrive at Station 2.

11 seconds: take the train to Station 3.

12 seconds: arrive at Station 3.

We will travel from Station 2 as follows:

10 seconds: take the train to Station 3.

11 seconds: arrive at Station 3.

Note that we should print 0 for Station 3.

Sample Input 2

4
12 24 6
52 16 4
99 2 2

Sample Output 2

187
167
101
0

Sample Input 3

4
12 13 1
44 17 17
66 4096 64

Sample Output 3

4162
4162
4162
0



Sample input:
3
6 5 1
1 10 1


Sample output:
12
11
0

Submission status: Accepted

Solution code:
N = int(input())
grid = [list(map(int, input().split())) for _ in range(N-1)]
C = [c[0] for c in grid]
S = [s[1] for s in grid]
F = [f[2] for f in grid]

T = []
for n in range(N):
    t = 0
    for i in range(n, N-1):
        if S[i] >= t:
            d = S[i] - t + C[i]
        else:
            temp = (t - S[i])%F[i]
            if temp == 0:
                d = C[i]
            else:
                d = F[i] - temp + C[i]
        t += d
    T.append(t)

for t in T:
    print(t)

Submission status: Accepted

Solution code:
from math import ceil
n=int(input())
lst=[]
for i in range(n-1):
    lst.append(list(map(int,input().split())))
def neccesary_time(m):
    t=0
    for i in range(m,n-1):
        s=lst[i][1]
        if t<=s:
            t=s+lst[i][0]
        else:
            t=s+lst[i][2]*ceil((t-s)/lst[i][2])+lst[i][0]
    return t
for i in range(n-1):
    print(neccesary_time(i))
print(0)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest
# Problem C

if __name__ == '__main__':
    station_count = int(input())
    c, s, f = list(), list(), list()

    # HACK: More smarter.
    for _ in range(station_count - 1):
        line = list(map(int, input().split()))
        c.append(line[0])
        s.append(line[1])
        f.append(line[2])

    for i in range(station_count):
        elapsed_time = 0

        for j in range(i, station_count - 1):
            if elapsed_time < s[j]:
                elapsed_time = s[j]
            elif (elapsed_time % f[j]) == 0:
                pass
            else:
                elapsed_time = elapsed_time + f[j] - (elapsed_time % f[j])

            elapsed_time += c[j]

        print(elapsed_time)

Submission status: Accepted

Solution code:
n=int(input())
c,s,f=[],[],[]
for i in range(n-1):
    a=list(map(int,input().split()))
    c.append(a[0])
    s.append(a[1])
    f.append(a[2])
for i in range(n-1):
    tot=s[i]
    for j in range(i,n-1):
        tot+=c[j]
        if j!=n-2:
            if tot<s[j+1]: tot+=s[j+1]-tot
            else:
                if (tot-s[j+1])%f[j+1]!=0: tot+=f[j+1]-(tot-s[j+1])%f[j+1]
    print(tot)
print(0)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    C, S, F = [], [], []
    capnd, sapnd, fapnd = C.append, S.append, F.append
    for c, s, f in (map(int, input().split()) for _ in [0] * (N - 1)):
        capnd(c)
        sapnd(s)
        fapnd(f)

    for i in range(N):
        t = 0
        for j in range(i, N - 1):
            if t < S[j]:
                t = S[j]
            elif not t % F[j]:
                pass
            else:
                t = t + F[j] - t % F[j]
            t += C[j]
        print(t)

main()

Submission status: Accepted

Solution code:

N = int(input())
info = []
for i in range(1,N):
    info.append(tuple(map(int, input().split())))

for i in range(N):
    t = 0
    for j in range(i,N-1):
        if t < info[j][1]:
            t = info[j][1]
        elif t % info[j][2] == 0:
            pass
        else:
            t = t + info[j][2] - t % info[j][2]
        t += info[j][0]
    print(t)

Submission status: Accepted

Solution code:
from functools import lru_cache

def main():
    N = int(input())
    infos = []
    for i in range(1,N):
        infos.append(tuple(map(int, input().split())))

    for i in range(1,N):
        current_time = 0
        for station_number in range(i,N):
            current_time = next_arrival_time(current_time, infos[station_number -1])
        print(current_time)
    print(0)

@lru_cache(maxsize = 2**26)
def next_arrival_time(current_time, info):
    if current_time <= info[1]:
        return info[1] + info[0]

    next_time = current_time
    remainder = next_time % info[2]
    while remainder != 0:
        next_time += 1
        remainder = next_time % info[2]
    while next_time < current_time:
        next_time += info[2]

    return next_time + info[0]

main()

Submission status: Accepted

Solution code:
n = int(input())
c,s,f = [0]*(n-1),[0]*(n-1),[0]*(n-1)
for i in range(n-1): c[i],s[i],f[i] = (int(i2) for i2 in input().split())
for j in range(n):
	answer = 0
	for k in range(j,n-1):
		if answer<s[k]: answer = s[k]
		elif answer%f[k]: answer += f[k]-(answer%f[k])
		answer += c[k]
	print(answer)

Submission status: Accepted

Solution code:
import math

N=int(input())

C=[]
S=[]
F=[]
for i in range(N-1):
    c,s,f=map(int, input().split())
    C.append(c)
    S.append(s)
    F.append(f)

T=[]
for i in range(N-1):
    s=S[i]+C[i]
    for j in range(i+1,N-1):
        if s<S[j]:
            s=S[j]
        elif s%F[j]!=0:
            s+=F[j]-(s%F[j])
        s+=C[j]
    T.append(s)

for i in range(N-1):
    print(T[i])
print(0)

Submission status: Accepted

Solution code:
N = int(input())-1
timeLine = [[0 for x in range(3)] for y in range(N)]
for i in range(N):
    tmp = input().split()
    timeLine[i][0],timeLine[i][1],timeLine[i][2] = int(tmp[0]),int(tmp[1]),int(tmp[2])
for j in range(N):
    total = timeLine[j][0] + timeLine[j][1]
    now = j+1
    while now <= (N-1):
        if timeLine[now][1] >= total:
            total = timeLine[now][1] + timeLine[now][0]
        else:
            if timeLine[now][1] + timeLine[now][2] >= total:
                total = timeLine[now][0] + timeLine[now][1] + timeLine[now][2]
            else:
                n = int((total-timeLine[now][1])/timeLine[now][2])
                if (total-timeLine[now][1]) % timeLine[now][2] > 0:
                    n += 1
                total = timeLine[now][0] + timeLine[now][1] + timeLine[now][2] * n
        now +=1
    print(total)
print(0)

Submission status: Accepted

Solution code:
n = int(input())
c = [0]*(n-1)
s = [0]*(n-1)
f = [0]*(n-1)

for i in range(n-1):
    c[i],s[i],f[i] = map(int,input().split())
for i in range(n):
    t = 0
    for j in range(i,n-1):
        if(t<s[j]):
            t = s[j]
        elif(t%f[j]):
            t += f[j]-(t%f[j])
        t += c[j]
    print(t)

Submission status: Accepted

Solution code:
N = int(input())
CSF = [list(map(int, input().split())) for i in range(N-1)]
time ={}
time[N] = 0

def timecal(i, now=0):
    if i == N:
        return now
    else:
        if now <= CSF[i-1][1]:
            return timecal(i+1, CSF[i-1][1] + CSF[i-1][0])
        else:
            return timecal(i+1, now + CSF[i-1][0] + (CSF[i-1][2] - now % CSF[i-1][2]) % CSF[i-1][2])

for i in range(1,N+1):
    print(timecal(i,0))

Submission status: Accepted

Solution code:
n = int(input())
data = [list(map(int,input().split())) for _ in range(n - 1)]
time = [0] * n
for i,arr in enumerate(data):
    for k in range(i+1):
        if arr[1] > time[k]:
            time[k] = arr[0] + arr[1]
        elif time[k] % arr[2] == 0:
            time[k] += arr[0]
        else:
            time[k] += arr[2] - (time[k] % arr[2]) + arr[0]

for i in time:
    print(i)

Submission status: Accepted

Solution code:
N = int(input())
stations = [ list(map(int, input().split())) for _ in range(N-1)]

time = [0] * N


for i, station in enumerate(stations):
    C, S, F = station
    for j in range(i + 1):
        if S > time[j]:
            time[j] = S + C
        elif time[j] % F == 0:
            time[j] += C
        else:
            time[j] += F - (time[j] % F) + C

[ print(t) for t in time ]

Submission status: Accepted

Solution code:
N = int(input())
c = []
s = []
f = []

for i in range(N-1):
    _c, _s, _f = map(int, input().split())
    c.append(_c)
    s.append(_s)
    f.append(_f)


for i in range(N):
    sumTime = 0
    stationNumber = i
    #print("(●・▽・●)",stationNumber)
    while stationNumber < N - 1:
        #print("(●・▽・●)(●・▽・●)", stationNumber, sumTime)
        if sumTime <= s[stationNumber]:
            sumTime = s[stationNumber]

        if (sumTime - s[stationNumber]) % f[stationNumber] == 0:
            sumTime += c[stationNumber]
            stationNumber += 1
        else:
            sumTime += f[stationNumber] - (sumTime - s[stationNumber]) % f[stationNumber]

    print(sumTime)

Submission status: Accepted

Solution code:
import math
def find(stations, start):
	currentT=stations[start][1]
	currentS=start
	while currentS != len(stations):
		C=stations[currentS][0]
		S=stations[currentS][1]
		F=stations[currentS][2]

		if currentT < S:
			currentT=S
		tmp=math.ceil((currentT-S)/F)
		currentT=S+tmp*F+C
		currentS+=1
	return currentT

N=int(input())
stations=[]
for i in range(N-1):
	stations.append([int(i) for i in input().split()])
for i in range(N-1):
	print(find(stations, i))
print(0)

Submission status: Accepted

Solution code:
n=int(input())
c=[0for i in range(n)]
s=[0for i in range(n)]
f=[0for i in range(n)]
for i in range(n-1):
  c[i],s[i],f[i]=map(int,input().split())
for i in range(n):
  time=0
  for j in range(i,n-1):
    if(time<=s[j]):
      time=s[j]+c[j]
    else:
      x=(time-s[j])//f[j]
      if(time%f[j]!=0):
        x+=1
      time=s[j]+f[j]*x+c[j]
  print(time)

Submission status: Accepted

Solution code:
N = int(input())

C = []
S = []
F = []
for i in range(N-1):
    c, s, f = list(map(int, input().split()))
    C.append(c)
    S.append(s)
    F.append(f)

for i in range(N):
    t = 0
    for j in range(i, N-1):
        if t < S[j]:
            t = S[j]
        elif t % F[j] == 0:
            pass
        else:
             t +=  F[j] - t % F[j]
        t += C[j]
    print(t)

Submission status: Accepted

Solution code:
N = int(raw_input())
C, S, F = [], [], []
for i in range(N-1):
	C_S_F = [int(num) for num in raw_input().split()]
	C.append(C_S_F[0])
	S.append(C_S_F[1])
	F.append(C_S_F[2])

def calc_time(i):
	Y = S[i] + C[i]
	for point in range(i, N-2):
		#print point, Y[point]
		Y = max((Y / F[point+1] + int((Y % F[point+1]) != 0)) * F[point+1], 
			S[point+1]) + C[point+1]
		#print i, point+1, Y[point+1], C[point+1]
	return Y

for i in range(N-1):
	print calc_time(i)

print 0

Submission status: Accepted

Solution code:
N = int(input())
li = []
for index in range(N-1):
	c, s, f = map(int, input().split())
	li.append((c, s, f))

for i in range(N):
	t = 0
	station = i
	while station < N-1:
		c, s, f = li[station]
		if t < s:
			t = s
			t += c
		else:
			t += (f-(t-s))%f + c
		station += 1
	print(t)

Submission status: Accepted

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys

def main():
    n = int(input())
    csf = tuple(tuple(map(int, line.split())) for line in sys.stdin.readlines())
    ans = []
    for i in range(n - 1):
        t = 0
        for c, s, f in csf[i:]:
            if t < s:
                t = s
            k, r = divmod(t - s, f)
            if r != 0:
                t = s + (k + 1) * f
            t += c
        ans.append(t)
    ans.append(0)

    print(*ans, sep='\n')

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
ST = []
    
for i in range(n-1):
    c,s,f = map(int,input().split())
    ST.append([c,s,f])


for i in range(n-1):    
    ans = ST[i][0] + ST[i][1]
    for j in range(i+1,n-1):
        if ans < ST[j][1]:
            ans = ST[j][1] +ST[j][0]
        elif (ans-ST[j][1])%ST[j][2] == 0:
                ans = ans + ST[j][0]
        else:
            ans = ans + ST[j][2] -(ans-ST[j][1])%ST[j][2] +ST[j][0]
    print(ans)
            
print('0')

Submission status: Accepted

Solution code:
n = int(input())
c,s,f = [],[],[]
ans = []
for i in range(n-1):
    ls = list(map(int, input().split()))
    c.append(ls[0])
    s.append(ls[1])
    f.append(ls[2])

for i in range(n-1):
    ans.append(s[i])
    ans[i] += c[i]
    for j in range(i+1,n-1):
        if ans[i]-s[j] >= 0:
            if (ans[i]-s[j])%f[j] == 0:
                ans[i] += c[j]
            else:
                ans[i] +=f[j]-((ans[i]-s[j])%f[j])+c[j]
        else:
            ans[i] += (s[j]-ans[i])+c[j]
ans.append(0)
for i in range(n):
    print(ans[i])

Submission status: Accepted

Solution code:
def main():
    N = int(input())

    times, start, interval = [], [], []
    for i in range(N-1):
        t, s, i = list(map(int, input().split()))
        times.append(t)
        start.append(s)
        interval.append(i)

    for src_station_idx in range(N-1):
        current_total_time = start[src_station_idx] + times[src_station_idx]

        for via_station_idx in range(src_station_idx+1, N-1):
            moving_time = times[via_station_idx]

            # 次に来る電車までの待ち時間を計測する
            if current_total_time <= start[via_station_idx]:
                waiting_time = start[via_station_idx] - current_total_time
            else:
                passed_time_from_start = current_total_time - start[via_station_idx]
                passed_time_from_before = passed_time_from_start % interval[via_station_idx]

                if passed_time_from_before == 0:
                    waiting_time = 0
                else:
                    waiting_time = interval[via_station_idx] - passed_time_from_before

            current_total_time += waiting_time + moving_time

        print(current_total_time)

    print(0)

main()

Submission status: Accepted

Solution code:
N = int(input())
CSF = [list(map(int, input().split())) for i in range(N-1)]

# 鉄道種類ループ
for i in range(N):
    T = 0
    # 鉄道乗り継ぎループ
    for j in range(i, N-1):
        if T < CSF[j][1]:
            T = CSF[j][1]
        else:
            if T % CSF[j][2] != 0:
                T += (CSF[j][2] - T % CSF[j][2])
        T += CSF[j][0]
    print(T)

Submission status: Accepted

Solution code:
def solve():
    n = int(input())
    c = []
    s = []
    f = []
    result = []
    for i in range(n - 1):
        tc, ts , tf = input().split()
        c.append(int(tc))
        s.append(int(ts))
        f.append(int(tf))
    for i in range(n):
        t = 0
        for j in range(i, n - 1):
            if t < s[j]:
                t = s[j]
            elif t % f[j] == 0:
                pass
            else:
                t = t + f[j] - (t % f[j])
            t = t + c[j]
        result.append(t)
    for i in range(n):
        print(result[i])
solve()

Submission status: Accepted

Solution code:
n = int(input())
ans = [0]*n
c, s, f = [], [], []
for i in range(n - 1):
    ct, st, ft = list(map(int, input().split()))
    c.append(ct)
    s.append(st)
    f.append(ft)

for i in range(n - 1):
    time = 0
    for j in range(i, n - 1):
        if(s[j] < time):
            if(time % f[j] != 0):
                time += f[j] - time % f[j]
        else:
            time += s[j] - time
        time += c[j]
    ans[i] = time

for i in range(n):
    print(ans[i])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
https://beta.atcoder.jp/contests/abc084/tasks/abc084_c

"""
import sys
from sys import stdin
from collections import namedtuple
from math import ceil
input = stdin.readline


def solve(trains, N):
    arrives = []

    for i in range(N-1):
        arrives.append(0)
        for j in range(len(arrives)):
            t = arrives[j] - trains[i].S
            dt = max(trains[i].S, (trains[i].S + ceil(t/trains[i].F)*trains[i].F ))
            arrives[j] = dt + trains[i].C

    arrives.append(0)
    return arrives


T = namedtuple('T', ['C', 'S', 'F'])
def main(args):
    trains = []
    N = int(input())
    for _ in range(N-1):
        c, s, f = map(int, input().split())
        trains.append(T(c, s, f))
    ans = solve(trains, N)
    print(*ans, sep='\n')


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
N = int(input())

time_list = []

for i in range(N - 1):
    C, S, F = map(int, input().split())
    time_list.append(C + S)
    for j in range(0, i):
        t = time_list[j]
        if t < S:
            time_list[j] += S - t + C
        elif t % F != 0:
            time_list[j] += F - t % F + C
        else:
            time_list[j] += C

time_list.append(0)

for time in time_list:
    print(time)

Submission status: Accepted

Solution code:
N = int(input())
t = [0 for i in range(N)]
csf = [list(map(int, input().split())) for i in range(N - 1)]
for i in range(N - 1):
	tmp_t = 0
	for j in range(i, N - 1):
		c, s, f = csf[j]
		if s >= tmp_t:
			tmp_t += s - tmp_t + c
		else:
			a = (tmp_t - s + f - 1) // f
			tmp_t += s + f * a - tmp_t + c
	print(tmp_t)
print(0)

Submission status: Accepted

Solution code:
N = int(input())
t = [0 for i in range(N)]
csf = [list(map(int, input().split())) for i in range(N - 1)]
for i in range(N - 1):
	tmp_t = 0
	for j in range(i, N - 1):
		c, s, f = csf[j]
		if s >= tmp_t:
			tmp_t += s - tmp_t + c
		else:
			a = (tmp_t - s + f - 1) // f
			tmp_t += s + f * a - tmp_t + c
	print(tmp_t)
print(0)

Submission status: Accepted

Solution code:

def main():
    N = int(input())

    x = [[int(a) for a in input().split()] for i in range(N - 1)]

    for i in range(N):
        time = 0
        for a in range(i, N-1):
            C = x[a][0]
            S = x[a][1]
            F = x[a][2]
            time = max(time, S)
            if time % F == 0:
                pass
            else:
                time = time + F - time % F
            time += C
        print(time)

main()

Submission status: Accepted

Solution code:
n = int(input())
c=[]
t=[]
f=[]
for v in range(n-1):
    cn, tn, fn = map(int,input().split())
    c.append(cn)
    t.append(tn)
    f.append(fn)

for q in range(n):
    time=0
    for p in range(q,n-1):
        if time>t[p]:
            while time%f[p]>0:
                time+=1
        else:
            time=t[p]
        time+=c[p]
    print(time)

Submission status: Accepted

Solution code:
N = int(input())
c = [0 for _ in range(N-1)]
s = [0 for _ in range(N-1)]
f = [0 for _ in range(N-1)]
for i in range(N-1):
    c[i], s[i], f[i] = map(int, input().split())

for (i, tmp_s) in enumerate(s):
    tmp_t = tmp_s 
    for j in range(i, N-1):
        if tmp_t<s[j]:
            delta = s[j] - tmp_t
        else:
            delta = f[j]-tmp_t%f[j]
        if delta==f[j]:
            delta = 0
        tmp_t = tmp_t + delta +c[j]
    print(tmp_t)

print(0)

Submission status: Accepted

Solution code:
n = int(input())
t = 0
st = 0
cn = []
sn = []
fn = []

for i in range(n-1):
  c,s,f = map(int,input().split())
  cn.append(c)
  sn.append(s)
  fn.append(f)

for j in range(n-1):
    t = 0
    for i in range(j,n-1):
      st = sn[i]
      if t <= sn[i]:
        t = sn[i]
      if t%fn[i] != 0:
          t += fn[i]-t%fn[i]
      t += cn[i]
    print(t)


print(0)

Submission status: Accepted

Solution code:
N = int(input())
C = []
S = []
F = []
for i in range(N-1):
    x, y, z = map(int, input().split(" "))
    C.append(x)
    S.append(y)
    F.append(z)

for j in range(N-1):
    ans = 0
    for k in range(j, N-1):
        if ans < S[k]:
            ans = S[k]
        if ans%F[k] != 0:
            ans += F[k]-ans%F[k]
        ans += C[k]
    print(ans)
print(0)

Submission status: Accepted

Solution code:
N = int(input())
X = list()

for i in range(0,N-1):
    X.append(list(map(int,input().strip().split(" "))))

for i in range(0, N):
    Y = 0
    for j in range(i, N-1):
        if Y <= X[j][1]:
            Y = X[j][1]
        else:
            if Y%X[j][2]==0:
                Y = Y
            else:
                Y = Y + X[j][2] - Y%X[j][2]
        Y += X[j][0]
    print(Y)

Submission status: Accepted

Solution code:
def F(Arri,S,F,C):
    if (Arri-S) <= 0:
        k=0
    else:
        k = (Arri-S) // F
        if (Arri-S) % F !=0:
            k += 1
    return S+F*k+C

N=int(input())
n=0
L=[]
l = [0,0,0]
while n < N-1:
    l[0],l[1],l[2] = map(int,input().split(' '))
    L.append(l.copy())
    n+=1
T = []
j = 0
while j < N-1:
    t=0
    t += L[j][0]+L[j][1]
    q=j+1
    while q < N-1:
        t = F(t,L[q][1],L[q][2],L[q][0])
        q += 1
    T.append(t)
    j += 1
T.append(0)
for i in T:
    print(i)

Submission status: Accepted

Solution code:
from math import ceil
n = int(input())
data = [list(map(int,input().split())) for i in range(n-1)]
ret = 0

for cnt in range(n):
    ret = 0
    for i in data:
        if ret <= i[1]:
            ret = i[1]
        else:
            ret = ceil(ret/i[2]) * i[2]
        ret += i[0]
    print(ret)
    if cnt != n-1 : data.pop(0)

Submission status: Accepted

Solution code:
#abc084c

n=int(raw_input())
l=[0 for i in xrange(n)]
for i in xrange(n-1):
 c,s,f=map(int,raw_input().split())
 for j in xrange(i+1):
  l[j]=max(s,(l[j]+f-1)/f*f)+c
for i in xrange(n):
 print l[i]

Submission status: Accepted

Solution code:
N = int(input())
n = 0
C = []
S = []
F = []
T = []
while n < N-1:
    c,s,f = map(int,input().split())
    C.append(c)
    S.append(s)
    F.append(f)
    n = n + 1
n = 0
while n < N-1:
    t = S[n]
    T.append(t)
    for i in range(n,N-1):
        if T[n]<=S[i]:
            T[n] = S[i]
        if T[n]%F[i] != 0:
            a = T[n]%F[i]
            T[n] = T[n] + F[i] - a
        T[n] = T[n] + C[i]
    print(T[n])
    n = n+1
print(0)

Submission status: Accepted

Solution code:
N = int(input())
C = []
S = []
F = []
for i in range(N - 1):
    c, s, f = map(int, input().split())
    C.append(c)
    S.append(s)
    F.append(f)
for i in range(N - 1):
    t = 0
    for j in range(i, N - 1):
        if t < S[j]:
            t = S[j]
        if t % F[j] != 0:
            t += F[j] - t % F[j]
        t += C[j]
    print(t)
print(0)

Submission status: Accepted

Solution code:


class Diagram:
    def __init__(self, n, xs):
        self.n = n
        self.xs = xs + [[0, 0, 0]]

    def departure(self, i, t):
        if i == self.n - 1:
            return t
        s = self.xs[i][1]
        f = self.xs[i][2]
        c = s // f
        x = max(s, t)
        d, m = divmod(x, f)
        if m == 0:
            return x
        else:
            return f*(d+1)

    def arrival(self, i, t):
        return self.departure(i, t) + self.xs[i][0]



if __name__ == "__main__":
    n = int(input())
    xs = [list(map(int, input().split())) for i in range(n-1)]
    d = Diagram(n, xs)

    ys = [0]*n
    for i in range(n):
        for j in range(i,n) :
            ys[i] = d.arrival(j, ys[i])
    for y in ys:
        print(y)

Submission status: Accepted

Solution code:


n = int(input())
c = [0] * (n + 1)
s = [0] * (n + 1)
f = [0] * (n + 1)

for i in range(1, n):
    x, y, z = map(int, input().strip().split( ' '))
    c[i] = x
    s[i] = y
    f[i] = z

def time(i, after=0):
    #print(i, after, c[i], s[i], f[i])
    if i == n:
        return after
    if (after < s[i]):
        start_time = s[i]
    else:
        if (after - s[i]) % f[i] == 0:
            start_time = after
        else:
            start_time = ((after - s[i])  // f[i] + 1) * f[i] + s[i]
    return time(i + 1, after=start_time+c[i])

for i in range(1,n+1):
    print(time(i))

Submission status: Accepted

Solution code:
import math
csf=[map(int,input().split())for _ in range(int(input())-1)]
ans=[0]
for c,s,f in csf:
    ans = [math.ceil(max(0,x-s)/f)*f+s+c for x in ans]+[0]
[print(x) for x in ans]

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
C = []
S = []
F = []
for i in range(N-1):
    Ci, Si, Fi = list(map(int, input().split((" "))))
    C.append(Ci)
    S.append(Si)
    F.append(Fi)

ans = []
for i in range(N):
    t = 0
    for j in range(i, N-1):
        if t < S[j]:
            t = S[j]
        elif t % F[j] == 0:
            pass
        else:
            t = t + F[j] - (t % F[j])
        t += C[j]
    print(t)

Submission status: Accepted

Solution code:
station_num = int(input())

if station_num == 1:
    print(0)
else:
    station_list = [[0, 0, 0] for i in range(station_num)]
    
    for i in range(station_num - 1):
        station_list[i] = input().split()
    # print(station_list)
    
    for i in range(station_num):
        count = int(station_list[i][0]) + int(station_list[i][1])
        now_position = i + 1
        while True:
            if now_position == station_num - 1 or now_position == station_num:
                print(count)
                break
            else:
                while True:
                    if count < int(station_list[now_position][1]):
                        count = int(station_list[now_position][1])
                    elif count % int(station_list[now_position][2]) == 0:
                        count += int(station_list[now_position][0])
                        now_position += 1
                        break
                    else:
                        count = count + int(station_list[now_position][2]) - (count % int(station_list[now_position][2]))

Submission status: Accepted

Solution code:
N = int(raw_input())
CSF = [map(int, raw_input().split()) for _ in range(N-1)]

for i in range(N):
    ans = 0
    for j in range(i, N-1):
        C, S, F = CSF[j][0], CSF[j][1], CSF[j][2]
        if ans < S:
            ans = S
        elif ans % F == 0:
            pass
        else:
            ans = (ans / F + 1) * F
        ans += C

    print ans

Submission status: Accepted

Solution code:
N=int(input())

C=[]
S=[]
F=[]
for i in range(N-1):
    c,s,f=map(int, input().split())
    C.append(c)
    S.append(s)
    F.append(f)

def func(n):
    t=0
    for i in range(n,N-1):
        if t < S[i]:
            t = S[i]
        else:
            if t%F[i]!=0:
                t += F[i] - (t % F[i])
        t += C[i]
    return t

for i in range(N):
    print(func(i))

Submission status: Accepted

Solution code:
N = int(raw_input())
CSF = [map(int, raw_input().split()) for _ in range(N-1)]

for i in range(N-1):
    ans = CSF[i][0] + CSF[i][1]
    for j in range(i+1, N-1):
        s, t, u = CSF[j][0], CSF[j][1], CSF[j][2]
        if t < ans:
            n = (ans - t) / u if ((ans - t) % u) == 0 else (ans - t) / u + 1
            ans = s + t + u * n
        else:
            ans = s + t

    print ans

print 0

Submission status: Accepted

Solution code:
N = int(input())
C = []
S = []
F = []
T = [0 for i in range(N)]

for i in range(N-1):
    c,s,f = map(int,input().split())
    C.append(c)
    S.append(s)
    F.append(f)

for i in range(1,N):
    time = S[-i] + C[-i]
    for j in range(1,i):
        if time < S[-(i-j)]:
            time = S[-(i-j)] + C[-(i-j)]
        else:
            dev = (time - S[-(i-j)]) % F[-(i-j)]
            if(dev != 0):
                time = (time + (F[-(i-j)] - dev) + C[-(i-j)])
            else:
                time = time + C[-(i-j)]
    T[-(i+1)] = time

for t in T:
    print(t)

Submission status: Accepted

Solution code:
N = int(input())
C = []
S = []
F = []
T = [0 for i in range(N)]

for i in range(N-1):
    c,s,f = map(int,input().split())
    C.append(c)
    S.append(s)
    F.append(f)

for i in range(1,N):
    time = 0
    if i == 1:
        #print(S[-i])
        time = S[-i] + C[-i]
    else:
        time = S[-i] + C[-i]
        for j in range(1,i):
            if time < S[-(i-j)]:
                time = S[-(i-j)] + C[-(i-j)]
            else:
                dev = (time - S[-(i-j)]) % F[-(i-j)]
                if(dev != 0):
                    time = (time + (F[-(i-j)] - dev) + C[-(i-j)])
                else:
                    time = time + C[-(i-j)]
    T[-(i+1)] = time

for t in T:
    print(t)

Submission status: Accepted

Solution code:
import numpy as np
import pdb

def main():
    N = int(raw_input())
    Cs = np.zeros(N-1).astype(int)
    Ss = np.zeros(N-1).astype(int)
    Fs = np.zeros(N-1).astype(int)

    for k in range(N-1):
        CSF = np.array(raw_input().split(' ')).astype(int)
        Cs[k] = CSF[0]
        Ss[k] = CSF[1]
        Fs[k] = CSF[2]

    schedule = train(Cs, Ss, Fs)
    for m in range(len(schedule)):
        print schedule[m]

def train(Cs, Ss, Fs):
    N = len(Cs)
    finaltimes = np.zeros(len(Cs) + 1).astype(int)
    arrivaltimes = 0
    destination = N - 1
    for k in range(N):
        currentloc = k
        arrivaltimes = Ss[k]
        for j in range(k, N):
            bestarrivaltimes = np.max([arrivaltimes, Ss[j]])
            arrivaltimes = np.ceil(bestarrivaltimes/ Fs[j]) * Fs[j] + Cs[j]
        finaltimes[k] = int(arrivaltimes)

    return finaltimes



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())

c = []
s = []
f = []
for i in range(N-1):
    l = list(map(int, input().split()))
    c.append(l[0])
    s.append(l[1])
    f.append(l[2])

ans = []
for i in range(N):
    t = 0
    for j in range(i, N-1):
        if t < s[j]:
            t = s[j]
        elif t % f[j] == 0:
            pass
        else:
            t += f[j] - (t % f[j])
        t += c[j]
    ans.append(t)

print('\n'.join(map(str, ans)))

Submission status: Accepted

Solution code:
N = int(input())

csf = [list(map(int, input().split())) for _ in range(N - 1)]
for i in range(N):
    t = 0
    for j in range(i, N - 1):
        c, s, f = csf[j]
        if t < s:
            t = s
        elif t % f == 0:
            t = t
        else:
            t = (t + f) - (t % f)
        t += c

    print(t)

Submission status: Accepted

Solution code:
N = int(input())
C = [0] * N
S = [0] * N
F = [0] * N
for i in range(N-1):
	C[i], S[i], F[i] = map(int, input().split())

def calc_time(i,t):
	global C,S,F

	res = 0
	if t < S[i]:
		res = S[i]
	elif t % F[i] == 0:
		res = t
	else:
		res = (t + F[i]) - (t % F[i])
	res += C[i]

	return res

ans = [[0 for i in range(N)] for _ in range(N)]
for i in range(N-1):
	for j in range(i,N-1):
		if j == 0:
			ans[i][j] = calc_time(j, 0)
		else:
			ans[i][j] = calc_time(j, ans[i][j-1])

for i in range(N):
	print(ans[i][N-2])