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:
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt, ceil
from functools import lru_cache, reduce
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)

# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# ワーシャルフロイド (任意の2頂点の対に対して最短経路を求める)
# 計算量n^3 (nは頂点の数)
def warshall_floyd(d, n):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d


# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

# 素因数分解
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# 素数判定
def is_prime(n):
    if n <= 1:
        return False
    p = 2
    while True:
        if p ** 2 > n:
            break
        if n % p == 0:
            return False
        p += 1
    return True


# limit以下の素数を列挙
def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P

# 同じものを含む順列
def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        # set（集合）型で重複を削除、ソート
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret


# ここから書き始める
n = int(input())
c = [0 for i in range(n - 1)]
s = [0 for i in range(n - 1)]
f = [0 for i in range(n - 1)]
for i in range(n - 1):
    c[i], s[i], f[i] = map(int, input().split())
for i in range(n - 1):
    now = 0
    for j in range(i, n - 1):
        if now < s[j]:
            now = s[j] + c[j]
        else:
            now = -(-(now - s[j]) // f[j]) * f[j] + c[j] + s[j]
    print(now)
print(0)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

n=I()
lis=[LI() for i in range(n)]
for i in range(n-1):
    time=lis[i][1]+lis[i][0]
    pos=i+1
    #print(time,end=" ")
    #print(pos)
    while pos<n-1:
        if time<lis[pos][1]:
            time=lis[pos][1]
        if time%lis[pos][2]!=0:
            time+=(lis[pos][2]-time%lis[pos][2])
        time+=lis[pos][0]
        pos+=1
        #print(time,end=" ")
        #print(pos)
    print(time)
print(0)

Submission status: Accepted

Solution code:
n = int(input())
C = []
S = []
F = []
for _ 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-2):
  ans = C[i]+S[i]
  for j in range(i+1, n-1):
    if S[j] >= ans:
      ans += (S[j]-ans) + C[j]
    else:
      if (ans-S[j])%F[j] == 0: ans += C[j]
      else: ans += F[j] - (ans-S[j])%F[j] + C[j]
  print(ans)
print(C[-1]+S[-1])
print(0)

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

from math import ceil

n = ni()
csf = nan(n - 1)

ans = []
for i in range(n - 1):
    c, s, f = csf[i]
    cur = s + c
    for j in range(i + 1, n - 1):
        nc, ns, nf = csf[j]
        cur = max(ceil(cur / nf) * nf, ns) + nc
    ans.append(cur)
ans.append(0)

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

Submission status: Accepted

Solution code:
import sys, math
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**20
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()

def resolve():
    N = I()
    CSF = [LI() for _ in range(N-1)]

    for i in range(N-1):
        arrival_time = 0
        for j in range(i, N-1):
            arrival_time = math.ceil(max(arrival_time, CSF[j][1])/CSF[j][2])*CSF[j][2] + CSF[j][0]
        print(arrival_time)
    print(0)

if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    info = [[int(x) for x in input().split()] for _ in range(n - 1)]
    answer = [0 for _ in range(n)]
    for i in range(n - 2, -1, -1):
        now = info[i][1]
        for j in range(i, n - 1):
            if j > i and now % info[j][2]:
                now += info[j][2] - now % info[j][2]
            now = max(now, info[j][1])
            now += info[j][0]
        answer[i] = now
    print("\n".join(map(str, answer)))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())

ans = [0]*N
for i in range(N-1):
    c,s,f = map(int,input().split())
    ans[i] += s+c
    for j in range(i):
        ans[j] = max((ans[j]+f-1)//f*f, s)+c
for a in ans:
    print(a)

Submission status: Accepted

Solution code:
N = int(input())

ans = [0]*N
for i in range(N-1):
    c,s,f = map(int,input().split())
    ans[i] += c+s
    for j in range(i):
        ans[j] = max((ans[j]+f-1)//f*f, s)+c
for a in ans:
    print(a)

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]=map(int,input().split())

for i in range(N-1):
    time=0
    for j in range(i,N-1):
        if time%F[j]==0:
            if time>=S[j]:
                time+=C[j]
            else:
                time=S[j]
                time+=C[j]
        else:
            if time>=S[j]:
                time+=F[j]-time%F[j]
                time+=C[j]
            else:
                time=S[j]
                time+=C[j]
    print(time)
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)

ans=[0]*n
for i in range(n-1):
    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]+1)*F[j]
        t+=C[j]
    ans[i]=t

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

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 - 1):
    a = 0
    for j in range(i, n - 1):
        if a <= s[j]:
            a = s[j]
        else:
            b = a - s[j]
            if b % f[j] > 0:
                a -= b
                a += (b // f[j]) * f[j]
                a += f[j]
        a += c[j]
    print(a)
print(0)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
csf = [list(map(int, readline().split())) for _ in range(n - 1)]
for i, (c, s, _) in enumerate(csf):
    s += c
    for cc, ss, ff in csf[i + 1:]:
        if s < ss:
            s = ss
        elif s % ff != 0:
            s += ff - (s % ff)
        s += cc
    print(s)
print(0)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc084/tasks/abc084_c
n = int(input())

trains = []
for _ in range(n - 1):
    c, s, f = map(int, input().split())
    trains.append((c, s, f))


ans = []
for i in range(n - 1):
    _c, start, _ = trains[i]
    t = start + _c
    for j in range(i + 1, n - 1):
        c, s, f = trains[j]
        if t > s:
            while t > s:
                s += f
            t += (s - t) + c
        else:
            t = s + c
    ans.append(t)
ans.append(0)
for a in ans:
    print(a)

Submission status: Accepted

Solution code:
import math
n = int(input())
c = [0]*(n-1)
s = [0]*(n-1)
f = [0]*(n-1)
for i in range(n-1):
  ci,si,fi = map(int,input().split())
  c[i] = ci
  s[i] = si
  f[i] = fi
for i in range(n-1):
  x = s[i]
  for j in range(i,n-2):
    x += c[j]
    x = max(s[j+1],math.ceil(x/f[j+1])*f[j+1])
  x += c[n-2]
  print(x)
print(0)

Submission status: Accepted

Solution code:
N,*L = map(int, open(0).read().split())
ans = 0
inf = [0]*(N-1)
for i,(c,s,f) in enumerate(zip(*[iter(L)]*3)):
  inf[i] = (c,s,f)
for i in range(N-1):
  ans = 0
  for j in range(i,N-1):
    c,s,f = inf[j]
    m = ((ans-1)//f+1)*f
    ans = max(m,s)
    ans += c
  print(ans)
print(0)

Submission status: Accepted

Solution code:
n=int(input())
csf=[list(map(int,input().split())) for _ in range(n-1)]
#n=100000
#csf=[[1,0,1] for _ in range(n-1)]
for i in range(n-1):
    t=0
    for j in range(i,n-1):
        t=max(csf[j][1],t+(-t)%csf[j][2])+csf[j][0]
    print(t)
print(0)

Submission status: Accepted

Solution code:
n = int(input())
c = []
s = []
f = []
for i in range(n - 1):
    ci, si, fi = map(int, input().split())
    c.append(ci)
    s.append(si)
    f.append(fi)
#c, s, f
for i in range(n - 1):
    time = s[i] + c[i]
    for j in range(i + 1, n - 1):
        if time < s[j]:
            time = s[j] + c[j]
        elif time % f[j] != 0:
            time += f[j] - time % f[j] + c[j]
        else:
            time += c[j]
    print(time)
print(0)

Submission status: Accepted

Solution code:
import math
n = int(input())
st = [list(map(int, input().split())) for i in range(n-1)]
for j in range(n-1):
    t = st[j][1]+st[j][0]
    for i in range(j+1,n-1):
        if t<st[i][1]:
            t = st[i][1]
        elif (t-st[i][1])%st[i][2]!=0:
            t += st[i][2]-(t-st[i][1])%st[i][2]
        t += st[i][0]
    print(t)
print(0)

Submission status: Accepted

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

for i in range(N-1):
    ans = 0
    ans += csf[i][1] + csf[i][0]
    for j in range(i+1, N-1):
        if ans >= csf[j][1]:
            if ans % csf[j][2] == 0:
                ans += csf[j][0]
            else:
                ans += csf[j][2] - (ans % csf[j][2]) + csf[j][0]
        else:
            ans = csf[j][1] + csf[j][0]
    
    print(ans)
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-1):
    t=s[i]+c[i]
    for j in range(i+1,n-1):
        if t<s[j]:
            t=s[j]+c[j]
        elif t%f[j]==0:
            t+=c[j]
        else:
            t+=f[j]-t%f[j]+c[j]
    print(t)
print('0')

Submission status: Accepted

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

import math

for i in range(N):
    time = 0
    for csf in CSF[i:]:
        if time <= csf[1]:
            time = csf[1] + csf[0]
        else:
            time = math.ceil((time - csf[1]) / csf[2])*csf[2] + csf[1] + csf[0]
    print(time)

Submission status: Accepted

Solution code:
n = int(input())
csf = [list(map(int,input().split())) for i in range(n - 1)]
#(c, s, f) = i→i+1へc秒かかる。s秒後に発車し、その後はf秒おきに発車する

ans = [0] * n
for i in range(n - 1):
    temp_time = 0
    for j in range(i, n - 1):
        c, s, f = csf[j]
        if temp_time <= s:
            temp_time += s - temp_time + c

        else:
            temp = temp_time % f
            temp_time += (f - temp) % f + c
    ans[i] = temp_time
print(*ans, sep='\n')

Submission status: Accepted

Solution code:
from sys import stdin
N=list(map(int,stdin.readline().strip().split()))[0]
eki=[list(map(int,input().split())) for _ in range(N-1)]

for i in range(len(eki)):
    x = eki[i][1]+eki[i][0]
    for j in range(i+1,len(eki)):
        if eki[j][1] >x:
            x=eki[j][1]
            x += eki[j][0]
        elif x%eki[j][2]==0:x+=eki[j][0]
        else:
            x+=eki[j][0]+eki[j][2]-x%eki[j][2]
    print(x)
print(0)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline
import math

def main():
    N = int(readline())
    CSF = [list(map(int, readline().rstrip().split())) for _ in range(N-1)]
    
    for i in range(N):
        t = 0
        for c, s, f in CSF[i:]:
            m = (t - s) / f
            m = max(math.ceil(m), 0)
            t = s + f * m + c
        print(t)


if __name__ == '__main__':
    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]=map(int,input().split())
for j in range(n-1):
    t=s[j]+c[j]
    now=j+1
    while now<n-1:
        if s[now]<t:
            t=((-t)//f[now])*(-f[now])
        else:
            t=s[now]
        t+=c[now]
        now+=1
    print(t)
print(0)

Submission status: Accepted

Solution code:
n = int(input())
c = []
s = []
f = []
for i in range(n - 1):
  ci, si, fi = map(int, input().split())
  c.append(ci)
  s.append(si)
  f.append(fi)
for i in range(n):
  t = 0
  for j in range(i, n - 1):
    t = max(t, s[j])
    t = (t + f[j] - 1) // f[j] * f[j] + c[j]
  print(t)

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
N = int(readline())
CSF = [list(map(int, readline().split())) for _ in range(N-1)]
for i in range(N):
    time = 0
    for c, s, f in CSF[i:N-1]:
        if time < s:
            time = s
        else:
            time = (time+f-1)//f*f
        time += c
    print(time)

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
N = int(readline())
CSF = [tuple(map(int, readline().split())) for _ in range(N-1)]
for i in range(N):
    time = 0
    for c, s, f in CSF[i:N-1]:
        if time < s:
            time = s
        else:
            time = (time+f-1)//f*f
        time += c
    print(time)

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
N = int(readline())
CSF = []
for i in range(N-1):
    CSF.append(tuple(map(int, readline().split())))
for i in range(N):
    time = 0
    for c, s, f in CSF[i:N-1]:
        if time < s:
            time = s
        else:
            time = (time+f-1)//f*f
        time += c
    print(time)

Submission status: Accepted

Solution code:
N=int(input())
C=[] #i駅からi+1駅までC[i]秒で到着
S=[] #i駅からS[i]秒後に出発、それ以降はF[i]秒おき
F=[]

for _ 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=S[i]+C[i]
    for j in range(i+1,N-1):
        if t<=S[j]:
            t=S[j]
        elif t%F[j]!=0:
            t+=F[j]-t%F[j]
        t+=C[j]
    print(t)
print(0)

Submission status: Accepted

Solution code:
n = int(input())
l = [list(map(int,input().split())) for _ in range(n-1)]
#i番目駅からのスタート
for i in range(n):
  #時間
  t = 0
  for j in range(i,n-1):
    c,s,f = l[j]
    if t>=s:
      if t%f!=0:
        t += -(t%f)+f
      else:
        t += 0
    else:
      t += (s-t)
      if t%f!=0:
        t += -(t%f)+f
      else:
        t += 0
    t += c
  print(t)

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):
  j=i
  t=0
  while j<N-1:
    if t<=S[j]:
      t=S[j]
    else:
      tmp= t-S[j]
      s=tmp%F[j]
      if s!=0:
        t += F[j]-s
    #print(i,j,t)
    t += C[j]
    j +=1
  print(t)

Submission status: Accepted

Solution code:
import sys
## io
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
MIIZ = lambda: list(map(lambda x: x-1, MII()))
## dp
INIT_VAL = 0
MD2 = lambda d1,d2: [[INIT_VAL]*d2 for _ in range(d1)]
MD3 = lambda d1,d2,d3: [MD2(d2,d3) for _ in range(d1)]
## math
DIVC = lambda x,y: -(-x//y)
DIVF = lambda x,y: x//y


def main():
    n = II()
    tt = [MII() for _ in range(n-1)]
    for i in range(n):
        t = 0
        for c, s, f in tt[i:]:
            # 待ち時間の計算
            if t <= s:
                t = s
            elif t%f == 0:
                pass
            else:
                t += f - (t%f)
            # 電車移動時間を加算
            t += c
        print(t)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
## io
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
MIIZ = lambda: list(map(lambda x: x-1, MII()))
## dp
INIT_VAL = 0
MD2 = lambda d1,d2: [[INIT_VAL]*d2 for _ in range(d1)]
MD3 = lambda d1,d2,d3: [MD2(d2,d3) for _ in range(d1)]
## math
DIVC = lambda x,y: -(-x//y)
DIVF = lambda x,y: x//y
from collections import namedtuple

def main():
    n = II()
    tt = [MII() for _ in range(n-1)]
    for i in range(n-1):
        t = 0
        for j in range(i, n-1):
            c, s, f = tt[j]
            # 待ち時間の計算
            if t <= s:
                t = s
            elif t%f == 0:
                pass
            else:
                t += f - (t%f)
            # 電車移動時間を加算
            t += c
            pass
        print(t)
    print(0)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def abc084_c():
  n = int(input())
  train = [tuple(map(int, input().split())) for _ in range(n-1)]

  def arrive_time(st):
    time = 0
    for i in range(st, n-1):
      c, s, f = train[i]
      # 現在時刻(または最初の出発時刻)を、出発間隔で切り上げ除算して、出発タイミングを決める
      departure = f * ((max(time, s) + f - 1) // f)
      # 出発時刻＋所要時間
      time = departure + c
      #print('st {} departure {} -> st {} arrived {}'.format(i, departure, i+1, time))
    return time

  for i in range(n):
    ans = arrive_time(i)
    print(ans)

abc084_c()

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]!=0:
            t=t+f[j]-t%f[j]
        t+=c[j]
    print(t)

Submission status: Accepted

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

for i in range(N):
    t = 0
    for j in range(i, N - 1):
        if t <= lst_s[j]:
            t = lst_s[j]
        else:
            t = (t + lst_f[j] - 1) // lst_f[j] * lst_f[j]
        t += lst_c[j]
    print(t)

Submission status: Accepted

Solution code:
N=int(input())

csflist=[]
for i in range(N-1):
  c,s,f=map(int,input().split())
  csflist.append((c,s,f))
#print(csflist)

for i in range(N):
  sec=0
  for j in range(i,N-1):
    c,s,f=csflist[j]
    if sec<s:
      sec=s
    elif sec%f>0:
      sec+=f-(sec%f)
    sec+=c
    #print(i,j,sec)
  print(sec)

Submission status: Accepted

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

# 時刻tに駅iにいる時、駅i+1に到着する時刻を返す
def next(i,t):
    if t<=lst[i][1]:
        return lst[i][0]+lst[i][1]
    elif t%lst[i][2]==0:
        return t+lst[i][0]
    else:
        return t+lst[i][0]+lst[i][2]-(t%lst[i][2])

for i in range(n-1):
    time = 0
    for j in range(i,n-1):
        time = next(j,time)
    print(time)
print(0)

Submission status: Accepted

Solution code:
ma = lambda : map(int,input().split())
ni = lambda : int(input())
import math
ceil = math.ceil
n = ni()
csf = []
for i in range(n-1):
    csf.append(tuple(ma()))
for i in range(n-1):
    ans = csf[i][1] + csf[i][0]
    for j in range(i+1,n-1):
        if ans<=csf[j][1]:
            ans =csf[j][1]+csf[j][0]
        else:
            ans = ceil(ans/csf[j][2])*csf[j][2] +csf[j][0]
    print(ans)
print(0)

Submission status: Accepted

Solution code:
N=int(input())

csflist=[]
for i in range(N-1):
  c,s,f=map(int,input().split())
  csflist.append((c,s,f))
#print(csflist)

for i in range(N):
  sec=0
  for j in range(i,N-1):
    c,s,f=csflist[j]
    if sec<s:
      sec=s
    elif sec%f>0:
      sec+=f-(sec%f)
    sec+=c
    #print(i,j,sec)
  print(sec)

Submission status: Accepted

Solution code:
N=int(input())

csflist=[]
for i in range(N-1):
  c,s,f=map(int,input().split())
  csflist.append((c,s,f))
#print(csflist)

for i in range(N-1):
  sec=0
  for j in range(i,N-1):
    c,s,f=csflist[j]
    if sec<=s:
      sec=s
    else:
      sec=f*((sec-s-1)//f+1)+s
    sec+=c
    #print(i,j,sec)
  print(sec)
  
print(0)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    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]=map(int,input().split())
    for j in range(N):
        t=0
        for i in range(j,N-1):
            if t<=S[i]:
                t=S[i]
            else:
                t=-(-(t-S[i])//F[i])*F[i]+S[i]
            t+=C[i]
        print(t)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math

n = int(input())
csf = [list(map(int, input().split())) for i in range(n-1)]
ANS = []
for i in range(n):
  ans = 0
  for c,s,f in csf[i:]:
    if ans <= s:
      ans = s + c
    else:
      ans = s + math.ceil((ans-s)/f) * f + c
  ANS.append(ans)
for i in ANS:
  print(i)

Submission status: Accepted

Solution code:
n = int(input())
c_ls, s_ls, f_ls = [0] * n, [0] * n, [0] * n
for i in range(n-1):
    c,s,f = map(int,input().split())
    c_ls[i] = c
    s_ls[i] = s
    f_ls[i] = f
# sta_num + 1 駅までの時間を求める
def to_sta(time_used, sta_num):
    if time_used < s_ls[sta_num]:
        return s_ls[sta_num] + c_ls[sta_num]
    else:
        if (time_used - s_ls[sta_num]) % f_ls[sta_num] == 0:
            return time_used + c_ls[sta_num]
        else:
            return time_used + c_ls[sta_num] + f_ls[sta_num] - ((time_used - s_ls[sta_num]) % f_ls[sta_num])
for start in range(n):
    time_used = 0
    for nex in range(start, n-1):
        time_used = to_sta(time_used, nex)
    print(time_used)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
chk = []
for i in range(n-1):
  c = [int(i) for i in input().split()]
  chk.append(c)
  
if n == 1:
  print(0)
  exit()
  
for i in range(n-2):
  ans = chk[i][1]
  ans += chk[i][0]
  for j in range(i,n-2):
    if chk[j+1][1] > ans:
      ans = chk[j+1][1]+chk[j+1][0]
    else:
      p = (ans-chk[j+1][1]-1)//chk[j+1][2]+1
      #print(ans,p)
      ans = p*chk[j+1][2]+chk[j+1][1]+chk[j+1][0]
  print(ans)
print(chk[n-2][0]+chk[n-2][1])
print(0)

Submission status: Accepted

Solution code:
def main():
  N = int(input())
  CSF = [[int(_) for _ in input().split()] for __ in range(N-1)]
  for i in range(N-1):
    t = CSF[i][1] + CSF[i][0]
    for j in range(i+1, N-1):
      c, s, f = CSF[j]
      if t <= s:
        t = s + c
      else:
        k = (t - s + f - 1)//f
        t = s + k * f + c
    print(t)
  print(0)
  return

if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


def input():
    return sys.stdin.readline().rstrip()


if __name__ == '__main__':
    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, s, f = map(int, input().split())
        C[i] = c
        S[i] = s
        F[i] = f

    for i in range(N - 1):
        t = S[i]
        for j in range(i, N - 1):
            t += C[j]
            if j < N - 2:
                next_t = S[j + 1]
                if t > next_t:
                    next_t += math.ceil((t - next_t) / F[j + 1]) * F[j + 1]
                t = next_t
        print(t)
    print(0)

Submission status: Accepted

Solution code:
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


def input():
    return sys.stdin.readline().rstrip()


if __name__ == '__main__':
    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, s, f = map(int, input().split())
        C[i] = c
        S[i] = s
        F[i] = f

    for i in range(N - 1):
        t = S[i]
        for j in range(i, N - 1):
            t += C[j]
            if j < N - 2:
                next_t = S[j + 1]
                while t > next_t:
                    next_t += F[j + 1]
                t = next_t
        print(t)
    print(0)

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):
    time = 0
    for j in range(i,n-1):
        c = csf[j][0]
        s = csf[j][1]
        f = csf[j][2]
        if time < s:time =s
        elif time%f == 0:p = 1
        else:time +=f-(time%f)
        time +=c
    print(time)

Submission status: Accepted

Solution code:
# solution

import io
import sys
import math

data = int(input())

array = [list(map(int, input().split())) for _ in range(data-1)]

for i in range(data-1):
    counter = 0
    for j in range(i, data-1):
        if counter < array[j][1]:
            counter = array[j][1]
        elif counter % array[j][2] != 0:
            counter += array[j][2] - (counter % array[j][2])
 
        counter += array[j][0]
 
    print(counter)
print(0)