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
input = sys.stdin.readline

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-1):
    t = 0
    for j in range(i, n-1):
        c = C[j]
        s = S[j]
        f = F[j]

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

Submission status: Accepted

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

ans = []
for i, (ci, si, fi) in enumerate(CSF):
  now = si + ci
  for j in range(i+1, N-1):
    cj, sj, fj = CSF[j]
    now = max((-(-now//fj))*fj, sj) + cj
  ans.append(now)

ans.append(0)
print(*ans, sep='\n')

Submission status: Accepted

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
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

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####GCD#####
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

N = I()
data = ILL(N-1)


for i in range(N-1):
  now = 0
  for j in range(i,N-1):
    c,s,f = data[j]
    next_departure = max(s,-(-now//f)*f)
    now = next_departure+c
  print(now)
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):
    current = 0
    for j in range(i, n-1):
        if current < csf[j][1]:
            current = csf[j][1]
        if current % csf[j][2] != 0:
            current += csf[j][2] - (current % csf[j][2])
        current += csf[j][0]
    print(current)

Submission status: Accepted

Solution code:
def solve(n, t_list):

    ans = [t[1] for t in t_list]
    ans.append(0)
    for i, t in enumerate(t_list):
        for j in range(i+1):
            if ans[j] < t[1]:
                ans[j] += t[0]+(t[1] - ans[j])
            else:
                if ans[j] % t[2] == 0:
                    ans[j] += t[0]
                else:
                    ans[j] += t[0] + (ans[j] // t[2] + 1)*t[2] - ans[j]

    for i in ans:
        print(i)

if __name__ == "__main__":
    n = int(input())
    t_list = [[int(j) for j in input().split()] for i in range(n-1)]
    solve(n, t_list)

Submission status: Accepted

Solution code:
import math
def main():
  N = int(input())
  ans = [0] * N
  for i in range(N-1):
    c, s, f = map(int, input().split())
    for j in range(i + 1):
      ans[j] = f*max(math.ceil(ans[j]/f), math.ceil(s/f))+c
  for i in range(N):
    print(ans[i])
if __name__ == "__main__":
  main()

Submission status: Accepted

Solution code:
DEBUG = False

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

if DEBUG:
    print("CSF: {}".format(CSF))

for i in range(N-1):
    ans = 0
    for j in range(i, N-1):
        if DEBUG:
            print("i: {}, j: {}, ans: {}".format(i, j, ans))
        c, s, f = CSF[j]
        if ans < s:
            ans = s
        elif ans  % f != 0:
            ans += f - ans % f
        else:
            pass
        ans += c
    if DEBUG:
        print("i: {}, j:{}, ans:{}".format(i, j, ans))
    print(ans)
print(0)

Submission status: Accepted

Solution code:
n = int(input())
inputs = [list(map(int,input().split())) for i in range(n-1)]
out = []
for station_st in range(n-1):
    spend_time = inputs[station_st][1]+inputs[station_st][0] #次の駅に着く時間

    for st_num_cur in range(station_st+1,n-1):
        if spend_time < inputs[st_num_cur][1]:
            spend_time = inputs[st_num_cur][1]

        train_leave_time = inputs[st_num_cur][1] 
        train_i = 0
        wait_time = 0
        if (spend_time%inputs[st_num_cur][2])!=0:
            wait_time = inputs[st_num_cur][2] - (spend_time%inputs[st_num_cur][2])
        spend_time += wait_time + inputs[st_num_cur][0] #次の駅で乗れる電車が出発する時間
        #print("spend",wait_time,spend_time)
    print(spend_time)
print(0)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    trains = [list(map(int, input().split(' '))) for _ in range(N - 1)]
    ans = [0 for _ in range(N)]
    for i in range(N - 1):
        t = 0
        for train in trains[i:]:
            c, s, f = train
            wait_time = s - t if t <= s else (f - t) % f
            t += wait_time + c
        ans[i] = t
    for a in ans:
        print(a)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

for i in range(N):
    ans = 0
    for j in range(i, N-1):
        if j == i:
            ans += CSF[i][1]
            ans += CSF[i][0]
        else:
            if ans < CSF[j][1]:
                ans += CSF[j][1] - ans
            else:
                mod = (ans - CSF[j][1]) % CSF[j][2]
                if mod != 0:
                    ans += CSF[j][2] - mod
            ans += CSF[j][0]
    print(ans)

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] = list(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] - t) + c[j]
        else:
            tmp = (t - s[j]) % f[j]
            if tmp == 0:
                t += c[j]
            else:
                t += (f[j] - tmp) + c[j]
    print(t)

Submission status: Accepted

Solution code:
N = int(input())
memo = [0]*N
C = [0]*N
S = [0]*N
F = [0]*N



for i in range(N-1):
    Ci, Si, Fi = map(int, input().split())
    C[i], S[i], F[i] = Ci, Si, Fi

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

    print(t)

Submission status: Accepted

Solution code:
import math

ceil = math.ceil

def main():
    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):
            nxt = ceil((ans[j]-S)/F)
            ans[j] = max(0, nxt)*F + S + C
    
    for a in ans:
        print(a)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3


def main():
    N = int(input())
    C = [None] * (N-1)
    S = [None] * (N-1)
    F = [None] * (N-1)
    for i in range(N-1):
        C[i], S[i], F[i] = map(int, input().split())
    
    for i in range(N-1):
        ans = S[i]
        for j in range(i,N-1):
            if j > i:
                if ans <= S[j]:
                    ans = S[j]
                else:
                    if (ans - S[j]) % F[j] > 0:
                        ans += F[j] - (ans - S[j]) % F[j]
            ans += C[j]
        print(ans)
    print(0)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
csf = []
for i in range(n-1):
    t = list(map(int, input().split()))
    csf.append(t)

ans = []
for i in range(n-1):
    now = 0
    for c,s,f in csf[i:]:
        if now < s:
            now = s
        now += (s-now)%f+c
    ans.append(now)
ans.append(0)

for a in ans:
    print(a)

Submission status: Accepted

Solution code:
def mult(a,b):
    #a以上の最小のbの倍数
    d = (a-1)//b
    return b*(d+1)

def mov(CSF,st):
    N = len(CSF)
    time = 0
    for i in range(st,N):
        c,s,f = CSF[i][0],CSF[i][1],CSF[i][2]
        time = max(time,s)
        time = mult(time,f) + c
    return time

def main():
    N = int(input())
    CSF = [list(map(int,input().split())) for _ in range(N-1)]

    for i in range(N-1):
        print(mov(CSF,i))
    print(0)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import copy
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

N = getN()
train = []

for i in range(N - 1):
    c, s, f = getNM()
    train.append([c, s, f])

# sta~Nまで行くのにかかる時間を求める関数
def gotowest(sta):
    # sta ~ sta + 1まで
    time = train[sta][0] + train[sta][1]
    # sta + 1~ Nまで
    for j in range(sta + 1, N - 1):
        if time <= train[j][1]:
            # もし到着した時間が一本目の列車が出発する前なら
            time = train[j][0] + train[j][1]
        else:
            # 最初の一本のその次の便(train[j][1] + train[j][2]分後出発)から数えてwait本目の列車に乗る
            wait = ((time - train[j][1]) + train[j][2] - 1) // train[j][2]
            time = train[j][1] + (train[j][2] * wait) + train[j][0]
    return time

ans = []
for i in range(N - 1):
    ans.append(gotowest(i))
# N~Nまで（０分）
ans.append(0)
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import copy
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

N = getN()
train = []

for i in range(N - 1):
    c, s, f = getNM()
    train.append([c, s, f])

# sta~Nまで行くのにかかる時間を求める関数
def gotowest(sta):
    # 1 ~ 2まで
    time = train[sta][0] + train[sta][1]
    for j in range(sta + 1, N - 1):
        if time <= train[j][1]:
            time = train[j][0] + train[j][1]
                # 一本目の列車出発後
        else:
            # 最初の一本から数えてwait本目の列車に乗る
            wait = ((time - train[j][1]) + train[j][2] - 1) // train[j][2]
            time = train[j][1] + (train[j][2] * wait) + train[j][0]
    return time
    
ans = []
for i in range(N - 1):
    ans.append(gotowest(i))
# N~Nまで（０分）
ans.append(0)
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
n = int(input())
csf = []
for _ in range(n-1):
    c, s, f = map(int, input().split())
    csf.append((c, s, f))
ans = [0]*n
for i, (c, s, f) in enumerate(csf):
    for j in range(0, i+1):
        if ans[j] <= s:
            ans[j] = c+s
        else:
            ans[j] = (ans[j]+f-1)//f*f+c
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
import copy
n = int(input())
c = [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 < c[j][1]:
            t = c[j][1]
        elif t%c[j][2] == 0:
            pass
        else:
            t += c[j][2] - t%c[j][2]
        t += c[j][0]
    print(t)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

N = int(input())
data = []
for _ in range(N - 1):
    data.append(tuple(map(int, input().split())))

for i in range(N - 1):
    c_i, s_i, f_i = data[i] 
    ans = c_i + s_i
    if i == N - 2:
        print(ans)
        continue
    for j in range(i + 1, N - 1):
        c_j, s_j, f_j = data[j]
        if ans >= s_j:
            tmp = (ans - s_j) % f_j
            ans += c_j if tmp == 0 else f_j - tmp + c_j
        else:
            ans += s_j - ans + c_j
    print(ans)

print(0)

Submission status: Accepted

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

for i in range(n-1):
    x = 0
    for j in range(i, n-1):
        if x < ls[j][1]:
            x = ls[j][1] + ls[j][0]
        else:
            mod = x % ls[j][2]
            if mod == 0:
                time = 0
            else:
                time = ls[j][2] - mod
            x += time + ls[j][0]
    print(x)

print(0)

Submission status: Accepted

Solution code:
from math import ceil
n, *CSF = map(int, open(0).read().split())
A = []
for i in range(0, 3*(n-1), 3):
    t = 0
    for c, s, f in zip(CSF[i::3], CSF[i+1::3], CSF[i+2::3]):
        if t <= s:
            t = s + c
        else:
            t = ceil((t-s) / f) * f + s + c
    A.append(t)
A.append(0)
print(*A, sep='\n')

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:
            pass
        else:
            t += f - t % f

        t += c

    print(t)

Submission status: Accepted

Solution code:
N = int(input())
C, S, F = zip(*(tuple(map(int, input().split())) for _ in range(N - 1)))
for i in range(N - 1):
    total = S[i] + C[i]
    for j in range(i + 1, N - 1):
        if total <= S[j]:
            total = S[j]
        else:
            div, rem = divmod(total, F[j])
            total = (div + bool(rem)) * F[j]
        total += C[j]
    print(total)
print(0)

Submission status: Accepted

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

ans = [0]*(n)
ans[n-2] = csf[n-2][0] + csf[n-2][1] # go to the goal.
# print('ans', ans)
for i in range(n-3, -1, -1):
    # print('i =',i)
    ans_cur = csf[i][0] + csf[i][1] # go to the next station with 1st train. 
    for j in range(i+1, n-1):
        # print('j = ', j)
        if ans_cur < csf[j][1]: # arrive before 1st train.
            ans[i] = ans[j]
            break
        while ans_cur%csf[j][2] != 0:
            ans_cur += 1 # wait for next train.
        ans_cur += csf[j][0]
    else:
        ans[i] = ans_cur

for val in ans:
    print(val)

Submission status: Accepted

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

for i in range(N):
    if i==N-1:
        print(0)
    now=0
    for j in range(i,N-1):
        c,s,f=L[j]
        if now<s:
            now+=s-now
        if now%f!=0:
            now+=(f-now%f)
        now+=c
        if j==N-2:
            print(now)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import ceil
N = int(input())
dia = [0]*(N-1)
for i in range(N-1):
    c,s,f = map(int,input().split())
    dia[i] = (c,s,f)
for i in range(N-1):
    time = 0
    for j in range(i,N-1):
        c,s,f = dia[j]
        if time > s:
            x = (time - s)/f
            s += ceil(x)*f
        time =  s + c
    print(time)
print(0)

Submission status: Accepted

Solution code:
N = int(input())
dia = [0]*(N-1)
for i in range(N-1):
    c,s,f = map(int,input().split())
    dia[i] = (c,s,f)
for i in range(N-1):
    time = 0
    for j in range(i,N-1):
        c,s,f = dia[j]
        if time > s:
            x = (time - s)/f
            if x.is_integer():
                s += int(x)*f
            else:
                s += int(x+1)*f
        time =  s + c

        # while time > s:
        #     s += f
        # time = s + c

    print(time)
print(0)

Submission status: Accepted

Solution code:
N = int(input())
dia = []
for _ in range(N-1):
    c,s,f = map(int,input().split())
    dia.append((c,s,f))
for i in range(N-1):
    time = 0
    for j in range(i,N-1):
        c,s,f = dia[j]
        while time > s:
            s += f

        time = s + c
    print(time)
print(0)

Submission status: Accepted

Solution code:
N = int(input())

Cost = [0]
Start = [0]
Frequency = [0]
Ans = [0] * (N+1)

for __ in range(N-1):
    c, s, f = map(int, input().split())
    Cost.append(c)
    Start.append(s)
    Frequency.append(f)

for i in range(1, N):
    if Ans[i] != 0:
        print(Ans[i])
    else:
        Same = []
        now = 0
        for j in range(i, N):
            if now <= Start[j]:
                if Ans[j] != 0:
                    now = Ans[j]
                    break
                Same.append(j)
                now = Start[j] + Cost[j]
            else:
                tmp = (now-1) // Frequency[j]
                tim = (tmp + 1) * Frequency[j]
                now = tim + Cost[j]
        print(now)
        for k in Same:
            Ans[k] = now
print(0)

Submission status: Accepted

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

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


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

Submission status: Accepted

Solution code:
n = int(input())

csfn = [None] * (n - 1)
for i in range(n - 1):
    csfn[i] = list(map(int, input().split(' ')))

result = [0] * n

for i in range(n - 1):
    for j in range(0, i + 1):
        if csfn[i][1] > result[j]:
            result[j] += (csfn[i][1] - result[j])
        else:
            result[j] += (-result[j] % csfn[i][2])
        result[j] += csfn[i][0]
        
for r in result:
    print(r)

Submission status: Accepted

Solution code:
# region header
import sys
import math
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, factorial, log, sqrt, sin, cos
from operator import itemgetter
from string import ascii_lowercase, ascii_uppercase, digits
sys.setrecursionlimit(10**6)
rs = lambda: sys.stdin.readline().rstrip()
ri = lambda: int(rs())
rf = lambda: float(rs())
rs_ = lambda: [_ for _ in rs().split()]
ri_ = lambda: [int(_) for _ in rs().split()]
rf_ = lambda: [float(_) for _ in rs().split()]
INF = float('inf')
MOD = 10 ** 9 + 7
# endregion
N = ri()
C = [0] * (N - 1)
S = [0] * (N - 1)
F = [0] * (N - 1)
for i in range(N - 1):
    C[i], S[i], F[i] = ri_()
dp = [0] * N
for i in range(N):
    dp[i] = 0
    for j in range(i, N - 1):
        dp[j + 1] = C[j] + max(S[j], ceil(dp[j] / F[j]) * F[j])
    print(dp[N - 1])

Submission status: Accepted

Solution code:
n = int(input())

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

for i in range(n):
    time = 0
    for j in range(i,n-1):
        if time < table[j][1]:
            time = table[j][1]
        elif time > table[j][1]:
            if time % table[j][2] != 0:
                time += table[j][2] -(time%table[j][2])
        time += table[j][0]
    print(time)

Submission status: Accepted

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

ans = []
for i in range(n-1):
    c,s,f = pair[i]
    cnt = s + c
    for j in range(i+1,n-1):
        c,s,f = pair[j]
        s_ = max(s,((cnt - 1)//f+1)*f)
        cnt = s_ + c
    print(cnt)
print(0)

Submission status: Accepted

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

for start in range(N):
    time = 0
    current_i = start
    while current_i < N-1:
        if time >= Ss[current_i]:
            if time % Fs[current_i] == 0:
                time += Cs[current_i]
                current_i += 1
            else:
                time = Fs[current_i] * (time // Fs[current_i] + 1)
        else:
            time = Ss[current_i]

    print(time)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#https://atcoder.jp/contests/abc084/tasks/abc084_c

n=ii()
carr,sarr,farr=[],[],[]

for _ in range(n-1):
    c,s,f=mii()
    carr.append(c)
    sarr.append(s)
    farr.append(f)

ans = [0]*n

for start in range(n-1):
    for temp in range(start,n-1):
        if ans[start]<sarr[temp]:
            ans[start]=carr[temp]+sarr[temp]
        else:
            aa= farr[temp]-(ans[start]%farr[temp])
            if aa==farr[temp]:
                aa=0
            ans[start]+=aa+carr[temp]
        #print(ans)
print(*ans)

Submission status: Accepted

Solution code:
def main():
    from math import ceil

    n, *csf = map(int, open(0).read().split())
    csf = list(zip(csf[::3], csf[1::3], csf[2::3]))
    times = []
    for i in range(n):
        time = 0
        for c, s, f in csf[i:]:
            g = time > s
            time = s + int(g) * ceil((time - s) / f) * f + c
        times.append(str(time))

    ans = "\n".join(times)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    from math import ceil

    n, *csf = map(int, open(0).read().split())
    csf = list(zip(csf[::3], csf[1::3], csf[2::3]))
    ans = ""
    for i in range(n):
        time = 0
        for c, s, f in csf[i:]:
            if time <= s:
                time = s + c
            else:
                time = s + ceil((time - s) / f) * f + c            

        ans += str(time) + '\n'
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    from math import ceil

    n, *csf = map(int, open(0).read().split())
    csf = list(zip(csf[::3], csf[1::3], csf[2::3]))
    ans = ""
    for i in range(n):
        time = 0
        for c, s, f in csf[i:]:
            if time <= s:
                time = s
            else:
                time = s + ceil((time - s) / f) * f
            time += c
        
        ans += str(time) + '\n'
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    from math import ceil

    n, *csf = map(int, open(0).read().split())
    csf = list(zip(csf[::3], csf[1::3], csf[2::3]))
    for i in range(n):
        time = 0
        for c, s, f in csf[i:]:
            if time <= s:
                time = s
            else:
                time = s + ceil((time - s) / f) * f
            time += c
        print(time)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math
n = int(input())
all_li = []
for _ in range(n-1):
    tmp_li = list(map(int,input().split()))
    all_li.append(tmp_li)
if n == 1:
    tmp = all_li[0]
    print(tmp[0]+tmp[1])
    exit()
for i,a in enumerate(all_li):
    now = a[1]+a[0]
    #print(i,now,all_li[i+1:])
    for aa in all_li[i+1:]:
        x,y,z = (aa[0],aa[1],aa[2])
        if now <= y:
            now = y+x
        else:
            now = math.ceil((now-y)/z)*z + y + x
    print(now)
    now = 0
print(0)

Submission status: Accepted

Solution code:
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    N=int(readline())
    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,readline().split())

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

if __name__=="__main__":
    main()