Problem:


Score: 300 points

Problem Statement

In 2028 and after a continuous growth, AtCoder Inc. finally built an empire with six cities (City 1, 2, 3, 4, 5, 6)!

There are five means of transport in this empire:

Train: travels from City 1 to 2 in one minute. A train can occupy at most A people.

Bus: travels from City 2 to 3 in one minute. A bus can occupy at most B people.

Taxi: travels from City 3 to 4 in one minute. A taxi can occupy at most C people.

Airplane: travels from City 4 to 5 in one minute. An airplane can occupy at most D people.

Ship: travels from City 5 to 6 in one minute. A ship can occupy at most E people.

For each of them, one vehicle leaves the city at each integer time (time 0, 1, 2, ...).

There is a group of N people at City 1, and they all want to go to City 6.

At least how long does it take for all of them to reach there? 
You can ignore the time needed to transfer.  

Constraints

1 \leq N, A, B, C, D, E \leq 10^{15}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A
B
C
D
E

Output

Print the minimum time required for all of the people to reach City 6, in minutes.

Sample Input 1

5
3
2
4
3
5

Sample Output 1

7

One possible way to travel is as follows.
First, there are N = 5 people at City 1, as shown in the following image:

In the first minute, three people travels from City 1 to City 2 by train. Note that a train can only occupy at most three people.

In the second minute, the remaining two people travels from City 1 to City 2 by train, and two of the three people who were already at City 2 travels to City 3 by bus. Note that a bus can only occupy at most two people.

In the third minute, two people travels from City 2 to City 3 by train, and another two people travels from City 3 to City 4 by taxi.

From then on, if they continue traveling without stopping until they reach City 6, all of them can reach there in seven minutes.

There is no way for them to reach City 6 in 6 minutes or less.

Sample Input 2

10
123
123
123
123
123

Sample Output 2

5

All kinds of vehicles can occupy N = 10 people at a time.
Thus, if they continue traveling without stopping until they reach City 6, all of them can reach there in five minutes.  

Sample Input 3

10000000007
2
3
5
7
11

Sample Output 3

5000000008

Note that the input or output may not fit into a 32-bit integer type.



Sample input:
5
3
2
4
3
5


Sample output:
7

Submission status: Time Limit Exceeded

Solution code:
# C - Five Transportations 

N = int(input())
A,B,C,D,E = (int(input()),int(input()),int(input()),int(input()),int(input()))
        
turn = 0
x1,x2,x3,x4,x5 = 0,0,0,0,0
y1,y2,y3,y4,y5 = 0,0,0,0,0
x0 = N
y0 = N

while x0+x1+x2+x3+x4 != 0:
    turn += 1
    
    # Aの判定
    if x0 > A:
        y1 += A
        y0 -= A
    elif 0 < x0 <= A:
        y1 += x0
        y0 -= x0
    else:
        pass
    
    # Bの判定
    if x1 > B:
        y2 += B
        y1 -= B
    elif 0 < x1 <= B:
        y2 += x1
        y1 -= x1
    else:
        pass
    
    # Cの判定
    if x2 > C:
        y3 += C
        y2 -= C
    elif 0 < x2 <= C:
        y3 += x2
        y2 -= x2
    else:
        pass
     
    # Dの判定
    if x3 > D:
        y4 += D
        y3 -= D
    elif 0 < x3 <= D:
        y4 += x3
        y3 -= x3
    else:
        pass
        
    # Eの判定
    if x4 > E:
        y5 += E
        y4 -= E
    elif 0 < x4 <= E:
        y5 += x4
        y4 -= x4
    else:
        pass
    
    # x => y
    x0,x1,x2,x3,x4,x5 = y0,y1,y2,y3,y4,y5
    

print(turn)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
human=[0,0,0,0,0,0]
human[0]=n
time=0
while human[5]<n:
    if human[4]>=e:
        human[5]+=e
        human[4]-=e
    else:
        human[5]+=human[4]
        human[4]=0
        #5-6
    if human[3]>=d:
        human[4]+=d
        human[3]-=d
    else:
        human[4]+=human[3]
        human[3]=0
        #4-5
    if human[2]>=c:
        human[3]+=c
        human[2]-=c
    else:
        human[3]+=human[2]
        human[2]=0
        #3-4
    if human[1]>=b:
        human[2]+=b
        human[1]-=b
    else:
        human[2]+=human[1]
        human[1]=0
        #2-3
    if human[0]>=a:
        human[1]+=a
        human[0]-=a
    else:
        human[1]+=human[0]
        human[0]=0
        #1-2
    time += 1
print(time)

Submission status: Time Limit Exceeded

Solution code:
# coding:utf-8
import time

N = int(input())

mov = [int(input()) for i in range(5)]
# print(mov)

citys = [0]*5
citys[0] = N
# print(f"init ctiys: {citys}")

clear = False
_time = 0

while clear == False:
    _time +=1
    for j in range(4,0,-1):
        # print(f"useing mov is {mov[j]}, city is {citys[j]}, j: {j}")
        citys[j] = mov[j] + citys[j] if citys[j-1] - mov[j] >0 else citys[j-1] + citys[j]
        citys[j-1] = citys[j-1] - mov[j] if citys[j-1] - mov[j] >0 else 0
    if citys[4] == N:
        clear = True
        print(_time+1)
    # print(citys)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=int(input())
B=int(input())
C=int(input())
D=int(input())
E=int(input())

num = [N, 0, 0, 0, 0, 0]
time = 0
while num[5] < N:
  if num[4] < E:
    num[5] += num[4]
    num[4] = 0
  else:
    num[5] += E
    num[4] -= E
  if num[3] < D:
    num[4] += num[3]
    num[3] = 0
  else:
    num[4] += D
    num[3] -= D
  if num[2] < C:
    num[3] += num[2]
    num[2] = 0
  else:
    num[3] += C
    num[2] -= C
  if num[1] < B:
    num[2] += num[1]
    num[1] = 0
  else:
    num[2] += B
    num[1] -= B
  if num[0] < A:
    num[1] += num[0]
    num[0] = 0
  else:
    num[1] += A
    num[0] -= A
  time += 1
  
print(time)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
li = []
for i in range(5):
    li.append(int(input()))
   
ans = 0
li2 = [n,0,0,0,0,0]
while li2[5] != n:
    ans += 1
    for i in [4,3,2,1,0]:
        if li2[i] == 0:
            pass
        elif li2[i] >= li[i]:
            li2[i] -= li[i]
            li2[i+1] += li[i]
        else:
            li2[i+1] += li2[i]
            li2[i] = 0

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,a,b,c,d,e=[int(input()) for i in range(6)]
dist=[n,0,0,0,0,0]
move=[a,b,c,d,e,0]
t=0
while dist[5]<n:
  dist_t=[max(0,dist[0]-move[0])]
  for j in range(1,6):
    dist_t.append(max(0,dist[j]-move[j])+min(dist[j-1],move[j-1]))
  t=t+1
  dist=dist_t
print(t)

Submission status: Time Limit Exceeded

Solution code:
n,a,b,c,d,e=[int(input()) for i in range(6)]
dist=[n,0,0,0,0,0]
move=[a,b,c,d,e]
t=0
while dist[5]<n:
  dist[0]=max(0,dist[0]-move[0])
  for j in range(1,5):
    dist[j]=max(0,dist[j]-move[j])+min(dist[j-1],move[j-1])
  dist[5]=dist[5]+min(dist[4],move[4])
  t=t+1
print(t)

Submission status: Time Limit Exceeded

Solution code:
def move(member_num, trans):
    member_num[5] += min(trans[4], member_num[4])
    member_num[4] += \
        min(trans[3], member_num[3]) - min(trans[4], member_num[4])
    member_num[3] += \
        min(trans[2], member_num[2]) - min(trans[3], member_num[3])
    member_num[2] += \
        min(trans[1], member_num[1]) - min(trans[2], member_num[2])
    member_num[1] += \
        min(trans[0], member_num[0]) - min(trans[1], member_num[1])
    member_num[0] -= min(trans[0], member_num[0])

    return member_num

if __name__ == '__main__':
    N = int(input())
    A = int(input())
    B = int(input())
    C = int(input())
    D = int(input())
    E = int(input())

    trans_time = [A, B, C, D, E]
    member_num = [N, 0, 0, 0, 0, 0]
    time_count = 0
    while True:
        time_count += 1
        member_num = move(member_num, trans_time)
        if member_num[5] == N:
            break

    print(time_count)

Submission status: Time Limit Exceeded

Solution code:
n,a,b,c,d,e=[int(input()) for i in range(6)]
dist=[n,0,0,0,0,0]
move=[a,b,c,d,e]
t=0
while dist[5]<n:
  dist[0]=max(0,dist[0]-move[0])
  dist[5]=dist[5]+min(dist[4],move[4])
  for j in range(1,5):
    dist[j]=max(0,dist[j]-move[j])+min(dist[j-1],move[j-1])
  t=t+1
print(t)

Submission status: Time Limit Exceeded

Solution code:
# listの各要素に人数を格納. 一番後ろに全員たどり着いたら終わり

list = [0] * 6
n_move = []

N = int(input())

for i in range(5) : 
    n_move.append(int(input()))


list[0] += N
time = 0

while list[-1] < N : 
    for i in range(4, -1, -1) : 
        if n_move[i] <= list[i] : 
            list[i+1] += n_move[i]
            list[i] -= n_move[i]
        else : 
            list[i+1] += list[i]
            list[i] = 0
    time += 1
    
print(time)

Submission status: Time Limit Exceeded

Solution code:
import sys
from copy import copy

N = int(input())
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

# 時刻nに都市xにいる人数をI_x_n, 都市xで載せられる人数をJ_xとする
# I_x_n+1_prov = I_x_n - J_x (if I_x_n >= J_x)
# I_x_n+1_prov = 0           (if I_x_n < J_x)
# I_x_n+1 = I_x_n+1_prov + I_x-1_n (if I_x-1_n <= J_x-1)
# I_x_n+1 = I_x_n+1_prov+ J_x-1    (if I_x-1_n > J_x-1)
# 都市6の人数がNになった時が求める時刻である

# 以下仮想の都市0を加える
I = [0, N, 0, 0, 0, 0, 0]
I_buf = [0, 0, 0, 0, 0, 0, 0]
J = [0, A, B, C, D, E, 0]

time = 0
while(True):
    if sum(I) != N:
        sys.exit()
    if I[6] == N:
        print(time)
        break
    time += 1
    for num in range(1, 7, 1):
        if I[num] > J[num]:
            I_buf[num] = I[num] - J[num]
        else:
            I_buf[num] = 0

        if I[num - 1] > J[num - 1]:
            I_buf[num] += J[num - 1]
        else:
            I_buf[num] += I[num - 1]
    I = copy(I_buf)

Submission status: Time Limit Exceeded

Solution code:
N_moto = int(input())
ninzu = [0,0,0,0,0,N_moto]

syudan = []
for i in range(5):
    syudan.append(input())

syudan2 = [int(i) for i in syudan]
syudan2 = tuple(reversed(syudan2))
res_time = 0

while ninzu[0] < N_moto:
    n = 0
    while n < 5:
        if ninzu[n+1] != 0 and ninzu[n+1] >= syudan2[n]:
            ninzu[n+1] -= syudan2[n]
            ninzu[n] += syudan2[n]
        elif ninzu[n+1] != 0 and ninzu[n+1] < syudan2[n]:
            ninzu[n] += ninzu[n+1]
            ninzu[n+1] = 0
        n += 1
   
    res_time +=1
     
print(res_time)

Submission status: Time Limit Exceeded

Solution code:
N, A, B, C, D, E = [int(input()) for _ in range(6)]

towns = [N, 0, 0, 0, 0, 0]
moves = [A, B, C, D, E]
count = 0


def step():
    stack = [0, 0, 0, 0, 0]
    for i in range(5):
        stack[i] = min(towns[i], moves[i])
        towns[i] = max(0, towns[i] - moves[i])
    for i in range(5):
        towns[i+1] = towns[i+1] + stack[i]
    return towns


while True:
    count += 1
    if step()[-1] == N:
        break
print(count)

Submission status: Time Limit Exceeded

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

N = int(input())
# ボトルネックとなる制限人数を取得
mini = min([int(input()) for _ in range(5)])
# 都市2 以降で要する合計移動時間で初期化
time = 4

while N > 0:
    N -= mini
    time += 1

print(time)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
rules = [int(input()) for _ in range(5)]
mini = min(rules)

# 都市2 以降の合計移動時間で初期化
time = 4

while N > 0:
    N -= mini
    time += 1

print(time)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())
s = np.array([N, 0, 0, 0, 0])
m = np.array([A, B, C, D, E])
T = 0
while True:
    t = np.minimum(s, m)
    s -= t
    s[1:] += t[:-1]
    T += 1
    if np.max(s) == 0:
        break
print(T)

Submission status: Time Limit Exceeded

Solution code:
from numpy import array, zeros
IN_RANGE = 5


# 入力受け取り
N = int(input())
a_e = array([int(input()) for i in range(IN_RANGE)])


# どこに人がいるか
a_e_num = zeros(IN_RANGE+1)
a_e_num[0] = N


# 1分ずつの処理
minute = 0
while a_e_num[IN_RANGE] < N:
    minute += 1
    move_index = (a_e_num[:IN_RANGE] - a_e) >= 0
    move_num = a_e_num[:IN_RANGE].copy()
    move_num[move_index] = a_e[move_index]
    a_e_num[:IN_RANGE] = a_e_num[:IN_RANGE] - move_num
    a_e_num[1:] = a_e_num[1:] + move_num

print(minute)

Submission status: Time Limit Exceeded

Solution code:
#入力
N = int(input())
maxmembers={}
for i in range(5):
    maxmembers[i] = int(input())

citypeople = [N,0,0,0,0,0]
flag = bool(False)
time = 0
'''
for i in range(6):
    print(citypeople[i],end=' ')
print('')
'''
while True:
    for i in reversed(range(1,6)):
        if citypeople[i-1] > maxmembers[i-1]:
            citypeople[i] += maxmembers[i-1]
            citypeople[i-1] -= maxmembers[i-1]
        else:
            citypeople[i] += citypeople[i-1]
            citypeople[i-1] = 0
    time += 1
    """
    for i in range(6):
        print(citypeople[i],end=' ')
    print('')
    """
    if citypeople[5] == N:
        break

print(time)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n = int(raw_input())
a = []
count = 0
for i in range(5):
	a.append(int(raw_input()))
b = np.array(a)
num = np.array((n, 0, 0, 0, 0, 0))
move = np.empty(5, dtype=np.int)
while num[5] < n:
	for i in range(5):
		move[i] = min(num[i], b[i])
	num = num - np.hstack((move,0)) + np.hstack((0,move))
	count += 1

print count

Submission status: Time Limit Exceeded

Solution code:
array1 = [int(input()) for i in range(6)]
array2 = array1[1:6]
array2.append(0)
array3 = [array1[0], 0, 0, 0, 0, 0]
move = [0, 0, 0, 0, 0]
t = 0
while (array3[-1] != array1[0]):
  for i in range(5):
    if ( array3[i] >= array2[i]):
      move[i] = array2[i]
    else:
      if (array3[i] == 0):
        move[i] = 0
      else:
        move[i] = array3[i]
  for i in range(5):
    array3[i] = array3[i] - move[i]
    array3[i+1] = array3[i+1] + move[i]
  t += 1
print(t)

Submission status: Time Limit Exceeded

Solution code:
population = int(input())
a2b = int(input())
b2c = int(input())
c2d = int(input())
d2e = int(input())
e2f = int(input())
city = [population,0,0,0,0,0]
vehicle = [a2b,b2c,c2d,d2e,e2f]
time = 0
while(city[5]!=population):
    for i in range(5):
        if city[4-i] >= vehicle[4-i]:
            city[5-i] += vehicle[4-i]
            city[4-i] -= vehicle[4-i]
        else:
            city[5-i] += city[4-i]
            city[4-i] = 0
    time += 1

print(time)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!

n = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

human = [n,0,0,0,0,0]
next_human = [n,0,0,0,0,0]

t = 0

while not human[-1]==n:
    if not human[0] == 0:
        x = min(human[0], a)
        next_human[0] -= x
        next_human[1] += x
    if not human[1] == 0:
        x = min(human[1], b)
        next_human[1] -= x
        next_human[2] += x
    if not human[2] == 0:
        x = min(human[2], c)
        next_human[2] -= x
        next_human[3] += x
    if not human[3] == 0:
        x = min(human[3], d)
        next_human[3] -= x
        next_human[4] += x
    if not human[4] == 0:
        x = min(human[4], e)
        next_human[4] -= x
        next_human[5] += x
    t += 1
    human[:] = next_human[:]

print(t)

Submission status: Time Limit Exceeded

Solution code:
N,A,B,C,D,E=[int(input()) for i in range(6)]
a,b,c,d,e,f,T=[N,0,0,0,0,0,0]


def ship(station,destination,capacity):
    if station>=capacity:
        s=capacity
    else:
        s=station
    destination=destination+s
    station=station-s
    return station,destination

while True:
    if f==N:
        print(T)
        break
    if e!=0:
      e,f=ship(e,f,E)
    if d!=0:
      d,e=ship(d,e,D)
    if c!=0:
      c,d=ship(c,d,C)
    if b!=0:
      b,c=ship(b,c,B)
    if a!=0:
      a,b=ship(a,b,A)
    T=T+1

Submission status: Time Limit Exceeded

Solution code:
inputs=[int(input()) for i in range(6)]
N,A,B,C,D,E=inputs
a,b,c,d,e,f=[N,0,0,0,0,0]
T=0

def ship(station,destination,capacity):
    if station>=capacity:
        s=capacity
    else:
        s=station
    destination=destination+s
    station=station-s
    return station,destination

while True:
    if f==N:
        print(T)
        break
    if e!=0:
      e,f=ship(e,f,E)
    if d!=0:
      d,e=ship(d,e,D)
    if c!=0:
      c,d=ship(c,d,C)
    if b!=0:
      b,c=ship(b,c,B)
    if a!=0:
      a,b=ship(a,b,A)
    T=T+1

Submission status: Time Limit Exceeded

Solution code:
inputs=[int(input()) for i in range(6)]
N,A,B,C,D,E=inputs
a,b,c,d,e,f=[N,0,0,0,0,0]
T=0

def ship(station,destination,capacity):
    if station>=capacity:
        s=capacity
    else:
        s=station
    destination=destination+s
    station=station-s
    return station,destination

while True:
    if f==N:
        print(T)
        break
    e,f=ship(e,f,E)
    d,e=ship(d,e,D)
    c,d=ship(c,d,C)
    b,c=ship(b,c,B)
    a,b=ship(a,b,A)
    T=T+1

Submission status: Time Limit Exceeded

Solution code:
inputs=[int(input()) for i in range(6)]
N,A,B,C,D,E=inputs
a,b,c,d,e,f=[N,0,0,0,0,0]
T=0

def ship(station,destination,capacity):
    if station>=capacity:
        s=capacity
    else:
        s=station
    destination=destination+s
    
while True:
    T=T+1
    if f==N:
        print(T)
        break
    ship(a,b,A)
    ship(b,c,B)
    ship(c,d,C)
    ship(d,e,D)
    ship(e,f,E)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
AtoE = [0]*5
for i in range(5):
  AtoE[i] = int(input())

M = min(AtoE)

count = 0
while True:
  N -= M
  if N<0:
    break
  count += 1
  
print(count + 5)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

memo = [0,a,b,c,d,e]
x = [N,0,0,0,0,0]

cnt = 0
while x[5] != N:
    for i in range(5,0,-1):
        if x[i-1] >= memo[i]:
            x[i] += memo[i]
            x[i-1] -= memo[i]
        elif x[i-1] < memo[i]:
            x[i] += x[i-1]
            x[i-1] = 0

    cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

t = 0
a, b, c, d, e = 0, 0, 0, 0, 0
n = N

while(True):
    t += 1
    # calc minus
    x1 = A if n > A else n
    x2 = B if a > B else a
    x3 = C if b > C else b
    x4 = D if c > D else c
    x5 = E if d > E else d

    n -= x1
    a -= x2
    b -= x3
    c -= x4
    d -= x5

    # calc add
    a += x1
    b += x2
    c += x3
    d += x4
    e += x5

    if e >= N:
        break

print(t)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

t = 0
a, b, c, d, e = 0, 0, 0, 0, 0
n = N

while(True):
    t += 1
    # calc minus
    x1 = A if n > A else n
    x2 = B if a > B else a
    x3 = C if b > C else b
    x4 = D if c > D else c
    x5 = E if d > E else d

    n -= x1
    a -= x2
    b -= x3
    c -= x4
    d -= x5

    # calc add
    a += x1
    b += x2
    c += x3
    d += x4
    e += x5

    if e >= N:
        break

print(t)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())
ABC = [N,0,0,0,0]
time = 0
flag = 0
i = 0
while ABC[4] > 0 or flag == 0:
    if i >= 4:
        if ABC[4] >= E:
            ABC[4]-=E
        else:
            ABC[4]=0
    if i >= 3:
        if ABC[3] >= D:
            ABC[3]-=D
            ABC[4]+=D
            flag = 1
        else:
            ABC[4]+=ABC[3]
            flag = 1
            ABC[3]=0
    if i >= 2:
        if ABC[2] >= C:
            ABC[2]-=C
            ABC[3]+=C
        else:
            ABC[3]+=ABC[2]
            ABC[2]=0
    if i >= 1:
        if ABC[1] >= B:
            ABC[1]-=B
            ABC[2]+=B
        else:
            ABC[2]+=ABC[1]
            ABC[1]=0
    if ABC[0] >= A:
        ABC[0]-=A
        ABC[1]+=A
    else:
        ABC[1]+=ABC[0]
        ABC[0]=0
        
        
    time += 1
    i += 1
print(time)

Submission status: Time Limit Exceeded

Solution code:
from itertools import permutations, combinations
n=int(input())
num_per_min = [int(input()) for i in range(5)]
point = [n,0,0,0,0,0]
time = 0
while(True):
    zero_over_index = sorted([i for i in range(len(point)) if point[i] >0], reverse=True)
    for index in zero_over_index:
      if index != 5:
        if point[index] >= num_per_min[index]:
          point[index] = point[index] - num_per_min[index]
          point[index+1] = point[index+1] + num_per_min[index]
        else:
          point[index+1] = point[index+1] + point[index]
          point[index] = 0
    time+=1
    if point[5] == n:
        print(time)
        break

Submission status: Time Limit Exceeded

Solution code:
import copy
N = int(input())
capa = []
for i in range(5):
    capa.append(int(input()))

num_h = [N, 0, 0, 0, 0, 0]

i = 0
while num_h[5] < N:
    for j in range(5, 0, -1):
        if num_h[j-1] <= 0:
            continue
        if num_h[j-1] >= capa[j-1]:
            num_h[j-1] -= capa[j-1]
            num_h[j] += capa[j-1]
        else:
            num_h[j] += num_h[j-1]
            num_h[j-1] = 0
    i += 1

print(i)

Submission status: Time Limit Exceeded

Solution code:
a = [0,0,0,0,0]

c = int(input())
a[0] = int(input())
a[1] = int(input())
a[2] = int(input())
a[3] = int(input())
a[4] = int(input())

b = [c,0,0,0,0,0]

time = 0

while 1:
	if b[5] == c:
		break
	b[5]+=b[4]-max(0,b[4]-a[4])
	b[4]=max(0,b[4]-a[4])
	b[4]+=b[3]-max(0,b[3]-a[3])
	b[3]=max(0,b[3]-a[3])
	b[3]+=b[2]-max(0,b[2]-a[2])
	b[2]=max(0,b[2]-a[2])
	b[2]+=b[1]-max(0,b[1]-a[1])
	b[1]=max(0,b[1]-a[1])
	b[1]+=b[0]-max(0,b[0]-a[0])
	b[0]=max(0,b[0]-a[0])
	time += 1

print(time)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
lim = [int(input()) for i in range(5)]
now = [n,0,0,0,0,0]
t = 0
def move(town1,lim,now):
     if now[town1] <= lim[town1]:
          now[town1+1] += now[town1]
          now[town1] = 0
     else:
          now[town1] -= lim[town1]
          now[town1+1] += lim[town1]
     return now


while(now[5] != n):
     for i in range(5):
          now = move(4-i,lim,now)
     t += 1
print(t)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
inp = []
for _ in range(6):
    try:
        k = int(input())
    except EOFError:
        pass
    inp.append(k)
N, box = inp[0], [inp[1], inp[2], inp[3], inp[4], inp[5]]
time, people = 0, [N, 0, 0, 0, 0, 0]

while people[5] != N:
    deal = 0
    for ii in range(5):
        i = 4 - ii
        if people[i] == 0:
            continue
        elif people[i] <= box[i]:
            deal += people[i]
            people[i+1] += people[i]
            people[i] = 0
        #elif people[i] > box[i]:
        else:
            deal += people[i]
            people[i+1] += box[i]
            people[i] -= box[i]
        
        if deal >= N: break
    time += 1
    #print(people, time)
print(time)

Submission status: Time Limit Exceeded

Solution code:

n = int(input())
max_num = [int(input()) for i in range(5)]
place_num = {0:n,1:0,2:0,3:0,4:0,5:0}
count = 0

while(place_num[5] != n):
	trans_num = {0:0,1:0,2:0,3:0,4:0}
	for i in range(5):
		if(place_num[i] > 0):
			trans_num[i] = min(max_num[i],place_num[i])
	for i in range(6):
		if(i != 5):
			place_num[i] -= trans_num[i]
		if(i != 0):
			place_num[i] += trans_num[i-1]
	count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = []
for i in range(5):
    a.append(int(input()))
nn = [0] * 6
nn[0] = n
count = 0
while nn[5] != n:
    idou_1 = min(a[0],nn[0])
    idou_2 = min(a[1],nn[1])
    idou_3 = min(a[2],nn[2])
    idou_4 = min(a[3],nn[3])
    idou_5 = min(a[4],nn[4])
    nn[0] -= idou_1
    nn[1] += idou_1
    nn[1] -= idou_2
    nn[2] += idou_2
    nn[2] -= idou_3
    nn[3] += idou_3
    nn[3] -= idou_4
    nn[4] += idou_4
    nn[4] -= idou_5
    nn[5] += idou_5
    count += 1
    #if nn[5] == n:
        #break
    #print(nn)
print(count)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8

n = int(input())
capa = [int(input()) for _ in range(5)]
city_num = [n, 0, 0, 0, 0, 0]
transported = [0]*5
t = 0

while True:
	for i in range(5):
		if city_num[i] >= 1:
			transported[i] = min(city_num[i], capa[i])
		else:
			transported[i] = 0
	
	for i in range(5):		
		city_num[i] -= transported[i]
		city_num[i+1] += transported[i]
			
	t += 1
	if city_num[-1] == n:
		break
		
print(t)

Submission status: Time Limit Exceeded

Solution code:
k=int(input())
a=[]
for i in range(5):
    a.append(int(input()))
t=[0]*6
t[0]=k
count=0
while k!=t[5]: 
    for i in range(5,0,-1):
        t[i]+=min(a[i-1],t[i-1])
        t[i-1]-=min(a[i-1],t[i-1])    
    count+=1    
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
    
array = [n,0,0,0,0,0]

index = 0
while array[5] != n:
  index += 1
  if array[4]<e:
    array[5] = array[5] + array[4]
    array[4] = 0
  else:
    array[5] = array[5] + e
    array[4] = array[4] - e
    
  if array[3]<d:
    array[4] = array[4] + array[3]
    array[3] = 0
  else:
    array[4] = array[4] + d
    array[3] = array[3] - d
    
  if array[2]<c:
    array[3] = array[3] + array[2]
    array[2] = 0
  else:
    array[3] = array[3] + c
    array[2] = array[2] - c
    
  if array[1]<b:
    array[2] = array[2] + array[1]
    array[1] = 0
  else:
    array[2] = array[2] + b
    array[1] = array[1] - b

  if array[0]<a:
    array[1] = array[1] + array[0]
    array[0] = 0
  else:
    array[1] = array[1] + a
    array[0] = array[0] - a
    
    
    
print(index)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
# 移動させる人数
N =int(input())

# 移動できる人数
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

# 初期状態
GI_list = [N,0,0,0,0,0]
time = 0

while True:
  time += 1
  # E
  if E <= GI_list[4]:
    GI_list[5] = GI_list[5] + E
    GI_list[4] = GI_list[4] - E
  elif(GI_list[4] >0):
    GI_list[5] = GI_list[5] + GI_list[4]
    GI_list[4] = 0

  # D
  if D <= GI_list[3]:
    GI_list[4] = GI_list[4] + D
    GI_list[3] = GI_list[3] - D
  elif(GI_list[3] >0):
    GI_list[4] = GI_list[4] + GI_list[3]
    GI_list[3] = 0
    
  # C
  if C <= GI_list[2]:
    GI_list[3] = GI_list[3] + C
    GI_list[2] = GI_list[2] - C
  elif(GI_list[2] >0):
    GI_list[3] = GI_list[3] + GI_list[2]
    GI_list[2] = 0
    
  # B
  if B <= GI_list[1]:
    GI_list[2] = GI_list[2] + B
    GI_list[1] = GI_list[1] - B
  elif(GI_list[1] >0):
    GI_list[2] = GI_list[2] + GI_list[1]
    GI_list[1] = 0
    
  # A
  if A <= GI_list[0]:
    GI_list[1] = GI_list[1] + A
    GI_list[0] = GI_list[0] - A
  elif(GI_list[0] >0):
    GI_list[1] = GI_list[1] + GI_list[0]
    GI_list[0] = 0
    
#  print(GI_list)
#  print("---------------")
  
  if GI_list == [0,0,0,0,0,N]:
    break
print(str(time))

Submission status: Time Limit Exceeded

Solution code:
import copy

def num_of_apperances(num, lim):
    if num < lim:
        return num
    else:
        return lim

N = int(input())
P = [int(input()) for i in range(5)]
MAP = [0]*6

MAP[0] = N
tern = 0
while True:
    tmp = copy.deepcopy(MAP)
    for i in range(5):
        #print("num: {}, lim: {}".format(MAP[i], P[i]))
        tmp[i+1] = num_of_apperances(MAP[i], P[i])
        tmp[i] -= num_of_apperances(MAP[i], P[i])

    tern += 1
    MAP = copy.deepcopy(tmp)
    #print("{}: {}".format(tern, tmp))
    if tmp[5] == N:
        print(tern)
        break

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
s = [[n,a],[0,b],[0,c],[0,d],[0,e],[0,0]]
time = 0
while s[5][0] != n:
  for i in range(5):
    if s[4-i][0] <= s[4-i][1]:
      s[4-i+1][0] += s[4-i][0]
      s[4-i][0] = 0
    else:
      s[4-i+1][0] += s[4-i][1]
      s[4-i][0] = s[4-i][0] - s[4-i][1]
  time += 1
print(time)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

t = [ a, b, c, d, e]

n = [N, 0, 0, 0, 0, 0]

j = 0
while True:
    for i in range(4, -1, -1):
        if n[i] > 0:
            dn = n[i] if t[i] > n[i] else t[i]
            n[i+1] += dn
            n[i] -= dn
    j += 1

    flg = True
    for i in range(5):
        if n[i] > 0:
            flg = False
            break
    if flg:
        break

print(j)

Submission status: Time Limit Exceeded

Solution code:
a = [0,0,0,0,0]

c = int(input())
a[0] = int(input())
a[1] = int(input())
a[2] = int(input())
a[3] = int(input())
a[4] = int(input())

b = [c,0,0,0,0,0]

time = 0

while 1:
	if b[5] == c:
		break
	tmp=max(0,b[4]-a[4])
	b[5]+=b[4]-tmp
	b[4]=tmp
	tmp=max(0,b[3]-a[3])
	b[4]+=b[3]-tmp
	b[3]=tmp
	tmp=max(0,b[2]-a[2])
	b[3]+=b[2]-tmp
	b[2]=tmp
	tmp=max(0,b[1]-a[1])
	b[2]+=b[1]-tmp
	b[1]=tmp
	tmp=max(0,b[0]-a[0])
	b[1]+=b[0]-tmp
	b[0]=tmp
	time += 1

print(time)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
city_cap = [int(input()) for _ in range(5)]
city_human_num = [N, 0, 0, 0, 0, 0]
time = 0

while city_human_num[5] != N:
    pre = list(city_human_num)
    for i in range(5):
        flow = city_cap[i] if pre[i] - city_cap[i] > 0 else pre[i]
        city_human_num[i] -= flow
        city_human_num[i + 1] += flow
    time += 1
print(time)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, [input() for i in range(5)]))
b = [n, 0, 0, 0, 0, 0]

cnt = 0
while b[5] != n:
    for i in range(5):
        c = b[4-i] - a[4-i]
        if c > 0:
            b[5-i] += a[4-i]
            b[4-i] -= a[4-i]
        else:
            b[5-i] += b[4-i]
            b[4-i] = 0
    cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

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

# 人数
n = int(input())
# 乗れる人数
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

l = [a, b, c, d, e]
m = [n, 0, 0, 0, 0]

count = 0
while m.count(0) != len(m):
    count += 1
    for i in [4, 3, 2, 1, 0]:
        if m[i] != 0:
            mi = min([l[i], m[i]])
            m[i] -= mi
            if i < 4:
                m[i + 1] += mi

print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

items = [a, b, c, d, e]
pps = [0] * 5
pps[0] = n
time = 0
flg = True
while flg:
    carry = 0
    for i, (item, pp) in enumerate(zip(items, pps)):
        pp_bef = pp
        num = pp - item
        if num < 0:
            num = 0
        pps[i] = num + carry
        pp_aft = num
        carry = pp_bef - pp_aft
    time += 1
    if pps == [0] * 5:
        flg = False
print(time)

Submission status: Time Limit Exceeded

Solution code:
from decimal import Decimal, ROUND_UP
tmp = []
toshi = []
for i in range(0,6):
    if i == 0:
        toshi.append(int(input()))
    else:
        toshi.append(0)
        tmp.append(int(input()))
count = 0
turn = 1
while toshi[0]!=0 or toshi[1]!=0 or toshi[2]!=0 or toshi[3]!=0 or toshi[4]!=0:
    if (turn < 6):
        lp = turn
    else:
        lp = 5 
    for i in reversed(range(lp)):
        if toshi[i] > tmp[i]:
            toshi[i] = toshi[i] - tmp[i]
            toshi[i+1] += tmp[i]
        elif toshi[i] != 0:
            toshi[i+1] += toshi[i]
            toshi[i] = toshi[i] - toshi[i]
    count+=1
    turn += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
move = [int(input()) for i in range(5)]
men = [n,0,0,0,0,0]
cnt = 0
while(men[-1]!=n):
    for i in range(4,-1,-1):
        #print(i)
        #print(men)
        if(men[i]>0):
            for j in range(move[i]):
                men[i] -= 1
                men[i+1] += 1
                #print(men)
                if(men[i] == 0):
                    break



    cnt+=1
print(cnt)