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:
n = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
ans = 0
ls = [n, 0, 0, 0, 0, 0]
while ls[-1] != n:
    ans += 1
    lscp = ls[:]
    ls[0] = lscp[0] - min(a,lscp[0])
    ls[1] = lscp[1] - min(b, lscp[1]) + min(a, lscp[0])
    ls[2] = lscp[2] - min(c, lscp[2]) + min(b, lscp[1])
    ls[3] = lscp[3] - min(d, lscp[3]) + min(c, lscp[2])
    ls[4] = lscp[4] - min(e, lscp[4]) + min(d, lscp[3])
    ls[5] = lscp[5] + min(e, lscp[4])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
inList = []
startCnt = int(input())
goalCnt = 0
for i in range(5):
    inList.append(int(input()))
endCnt = startCnt
stausList = [0] * 5
cnt = 0
stausList[0] = startCnt
while goalCnt < endCnt:
    if inList[4] >= stausList[4]:
        goalCnt += stausList[4]
        stausList[4] = 0
    else:
        goalCnt += inList[4]
        stausList[4] -= inList[4]

    if stausList[4] == 0:
        if inList[3] >= stausList[3]:
            stausList[4] = stausList[3]
            stausList[3] = 0
        else:
            stausList[4] = inList[3]
            stausList[3] -= inList[3]
    else:
        if inList[3] >= abs(stausList[4] - stausList[3]):
            stausList[4] += abs(stausList[4] - stausList[3])
            stausList[3] -= abs(stausList[4] - stausList[3])
        else:
            stausList[4] += abs(stausList[4] - inList[3])
            stausList[3] -= abs(stausList[4] - inList[3])

    if stausList[3] == 0:
        if inList[2] >= stausList[2]:
            stausList[3] = stausList[2]
            stausList[2] = 0
        else:
            stausList[3] = inList[2]
            stausList[2] -= inList[2]
    else:
        if inList[2] >= abs(stausList[3] - stausList[2]):
            stausList[3] += abs(stausList[3] - stausList[2])
            stausList[2] -= abs(stausList[3] - stausList[2])
        else:
            stausList[3] += abs(stausList[3] - inList[2])
            stausList[2] -= abs(stausList[3] - inList[2])

    if stausList[2] == 0:
        if inList[1] >= stausList[1]:
            stausList[2] = stausList[1]
            stausList[1] = 0
        else:
            stausList[2] = inList[1]
            stausList[1] -= inList[1]
    else:
        if inList[1] >= abs(stausList[2] - stausList[1]):
            stausList[2] += abs(stausList[2] - stausList[1])
            stausList[1] -= abs(stausList[2] - stausList[1])
        else:
            stausList[2] += abs(stausList[2] - inList[1])
            stausList[1] -= abs(stausList[2] - inList[1])

    if stausList[1] == 0:
        if inList[0] >= stausList[0]:
            stausList[1] = stausList[0]
            stausList[0] = 0
        else:
            stausList[1] = inList[0]
            stausList[0] -= inList[0]
    else:
        if inList[0] >= abs(stausList[1] - stausList[0]):
            stausList[1] += abs(stausList[1] - stausList[0])
            stausList[0] -= abs(stausList[1] - stausList[0])
        else:
            stausList[1] += abs(stausList[1] - inList[0])
            stausList[0] -= abs(stausList[1] - inList[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 reversed(range(5)):
        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())
s = [input() for i in range(5)]
s = [int(i) for i in  s]
time = 0
road = [0 for i in range(6)]
road[0] = N
while(True):
    for i in range(5)[::-1]:
        moving_people_num = len(set(range(road[i])) & set(range(s[i]))) 
        road[i] -= moving_people_num
        road[i+1] += moving_people_num
    time += 1
    if road[5] == N:
        break
print(time)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
nums = [0]*5
for i in range(5):
    nums[i] = int(input())
board = [0]*6
board[0] = N
ans = 0
while True:
    # print(board)
    if board[5] == N:
        break
    mov = []
    for j in range(5):
        if board[j] > 0:
            mov.append(j)
    mov.sort(reverse=True)
    for k in mov:
        if board[k] < nums[k]:
            n = board[k]
        else:
            n = nums[k]
        board[k] -= n
        board[k+1] += n
    ans += 1

print(ans)

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())
time= 0

first = n
second = 0
third = 0
forth = 0
fifth = 0
goal = 0

while goal != n:
    time += 1


    #6
    if fifth < e:
        e_moved = fifth
    else:
        e_moved = e
    fifth = fifth - e_moved
    goal = goal + e_moved

    #5
    if forth < d:
        d_moved = forth
    else:
        d_moved = d
    forth = forth - d_moved
    fifth = fifth + d_moved

    #4
    if third < c:
        c_moved = third
    else:
        c_moved = c
    third = third - c_moved
    forth = forth + c_moved

    #3
    if second < b:
        b_moved = second
    else:
        b_moved = b
    second = second - b_moved
    third = third + b_moved

    #2
    if first < a:
        a_moved = first
    else:
        a_moved = a
    first = first - a_moved
    second = second + a_moved


print(time)

Submission status: Time Limit Exceeded

Solution code:
l = [0]*6
count=0
n = int(input())
t = list(map(int,[input() for _ in range(5)]))
l[0]=n

while 1:
    for i in range(5):
        if 0<l[4-i]<=t[4-i]:
            l[4-i+1] += l[4-i]
            l[4-i] = 0
        elif t[4-i]<l[4-i]:
            l[4-i+1]+=t[4-i]
            l[4-i]-=t[4-i]
    count+=1
    if l[5]==n:
        break
    
print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys

sys.setrecursionlimit(1000000000)

ap=a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
f=int(input())
bp=cp=dp=ep=fp=0
i=0
def idou(a,b,c,d,e,f,ap,bp,cp,dp,ep,fp):
    global i
    if a==fp:
        return i
    else:
        i+=1
        if ep != 0:
            if ep>=f:
                ep-=f
                fp+=f
            else:
                fp+=ep
                ep=0
        if dp != 0:
            if dp>=e:
                dp-=e
                ep+=e
            else:
                ep+=dp
                dp=0
        if cp != 0:
            if cp>=d:
                cp-=d
                dp+=d
            else:
                dp+=cp
                cp=0
        if bp != 0:
            if bp>=c:
                bp-=c
                cp+=c
            else:
                cp+=bp
                bp=0
        if ap != 0:
            if ap>=b:
                ap-=b
                bp=bp+b
            else:
                bp+=ap
                ap=0
        idou(a,b,c,d,e,f,ap,bp,cp,dp,ep,fp)
idou(a,b,c,d,e,f,ap,bp,cp,dp,ep,fp)
print(i)

Submission status: Time Limit Exceeded

Solution code:
k = []
for i in range(6):
    k.append(int(input() )) 

hito= [k[0],0,0,0,0,0]

deru = [0,0,0,0,0]
j = 0
while True:
    j = j+1
    #print(hito)
    #print(deru)
    for i in range(5):
        deru[i] = k[i + 1] if hito[i] - k[i + 1] >=0 else hito[i]

    for i in range(5):
        hito[i] = hito[i] - deru[i]
        hito[i + 1] = hito[i + 1] + deru[i]
    
    if  hito[5] == k[0]:
        break
    
print(j)

Submission status: Time Limit Exceeded

Solution code:
def move(start,end,city):
    if( a[start-1] > city[start]):
        # tmp1 = city[start]
        city[end] += city[start]
        city[start] = 0
    else:
        city[end] += a[start-1]
        city[start] -= a[start-1]
    return city

n = int(input())
a = [int(input()) for i in range(5)]
city = [0,n,0,0,0,0,0,0]

time = 0
while(city[6] < n):
    time += 1
    for i in range(5):
        city = move(5-i,6-i,city)
print(time)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=[int(input()) for i in range(5)]
p=[n, 0, 0, 0, 0, 0]
t=0
if min(s) >= n:
  print(5)
else:
  while p[5] != n:
    for i in range(5):
      if p[4-i] >= s[4-i]:
        p[4-i] -= s[4-i]
        to = s[4-i]
      else:
        to = p[4-i]
        p[4-i] = 0
      p[5-i] += to

    t+=1
  print(t)

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())

inputlist = []

inputlist.append(A)
inputlist.append(B)
inputlist.append(C)
inputlist.append(D)
inputlist.append(E)

#print("input:",inputlist)

tmpNumber = [0]*6

tmpNumber[0] = N
counter = 0
#print("start")
#print(tmpNumber)

while(True):
#	print("Time:", counter+1)
	for i in reversed(range(0,5)):
#		print("i:", i)
		if tmpNumber[i] == 0 and tmpNumber[i+1] == 0:
#		print("throught")
			continue
		if tmpNumber[i] > inputlist[i]:
			tmpNumber[i+1] += inputlist[i]
			tmpNumber[i] -= inputlist[i]
		else:
			tmpNumber[i+1] += tmpNumber[i]
			tmpNumber[i] = 0

#		print(tmpNumber)

	counter += 1
	if tmpNumber[5] == N:
		break
#print("finish")
#print("minutes:", counter)
print(counter)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=[int(input()) for i in range(5)]
a=s[0]
b=s[1]
c=s[2]
d=s[3]
e=s[4]
p=[n, 0, 0, 0, 0, 0]
t=0
while p[5] != n:
  for i in range(5):
    if p[4-i] >= s[4-i]:
      p[4-i] -= s[4-i]
      to = s[4-i]
    else:
      to = p[4-i]
      p[4-i] = 0
    p[5-i] += to

  t+=1
print(t)

Submission status: Time Limit Exceeded

Solution code:
A=list()
B=list()
for i in range(6):
  A.append(int(input()))
  B.append(0)
B[0]=A[0]
count=0
flag=B[1]!=0 or B[2]!=0 or B[3]!=0 or B[4]!=0
while flag or A[0]!=B[5]:
  for i in reversed(range(5)):
    if A[i+1]-B[i]<0:
      B[i+1]=A[i+1]
      B[i]=B[i]-A[i+1]
    else:
      B[i+1]+=B[i]
      B[i]=0
  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())

cap = [a, b, c, d, e]
city = [n, 0, 0, 0, 0, 0]

t = 0
while city[5] != n:
    schedule = [0, 0, 0, 0, 0, 0]
    t += 1
    for i in range(len(cap)):
        if city[i] < cap[i]:
            schedule[i + 1] += city[i]
            schedule[i] -= city[i]
        else:
            schedule[i] -= cap[i]
            schedule[i + 1] += cap[i]
    for i in range(len(schedule)):
        city[i] += schedule[i]
print(t)

Submission status: Time Limit Exceeded

Solution code:
n,a,b,c,d,e=[int(input()) for i in range(6)]

city1 = [n]
city2 = [0]
city3 = [0]
city4 = [0]
city5 = [0]
city6 = [0]

t = 0

while city6[t-1]<n:
    
    if city1[t]==0:
        city1.append(0)
        city2.append(city2[t])
    elif city1[t]>=a:
        city1.append(city1[t]-a)
        city2.append(city2[t]+a)
    else:
        city1.append(0)
        city2.append(city2[t]+city1[t])
    
    if city2[t]==0:
        city3.append(city3[t])
    elif city2[t]>=b:
        city2[t+1] -= b
        city3.append(city3[t]+b)
    else:
        city2[t+1] -= city2[t]
        city3.append(city3[t]+city2[t])
    
    if city3[t]==0:
        city4.append(city4[t])
    elif city3[t]>=c:
        city3[t+1] -= c
        city4.append(city4[t]+c)
    else:
        city3[t+1] -= city3[t]
        city4.append(city4[t]+city3[t])
    
    if city4[t]==0:
        city5.append(city5[t])
    elif city4[t]>=d:
        city4[t+1] -= d
        city5.append(city5[t]+d)
    else:
        city4[t+1] -= city4[t]
        city5.append(city5[t]+city4[t])
        
    if city5[t]==0:
        city6.append(city6[t])
    elif city5[t]>=e:
        city5[t+1] -= e
        city6.append(city6[t]+e)
    else:
        city5[t+1] -= city5[t]
        city6.append(city6[t]+city5[t])
        
    t += 1

print(t-1)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
N = int(input())
can_moves = []
can_moves.append(int(input()))
can_moves.append(int(input()))
can_moves.append(int(input()))
can_moves.append(int(input()))
can_moves.append(int(input()))
cities = [N, 0, 0, 0, 0, 0]
time = 0
for t in range(1, 10**15):
  for i in reversed(range(len(cities) - 1)):
    if cities[i] != 0:
      cities[i] -= can_moves[i]
      cities[i+1] += can_moves[i]
      if cities[i] < 0:
        cities[i+1] += cities[i]
        cities[i] = 0
  if cities[-1] == N:
    time = t
    # print(cities)
    break
  
# 出力
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())

class Transporter():
    def __init__(self, cap_out, temp=0):
        self.temp_num = temp
        self.cap_out = cap_out

    def transport(self):
        if self.temp_num < self.cap_out:
            num = self.temp_num
            self.temp_num = 0
            return num
        else:
            self.temp_num -= self.cap_out
            return self.cap_out

A_ = Transporter(A, temp=N)
B_ = Transporter(B)
C_ = Transporter(C)
D_ = Transporter(D)
E_ = Transporter(E)

time = 0
while (A_.temp_num!=0):
    time += 1
    a=A_.transport()
    b=B_.transport()
    c=C_.transport()
    d=D_.transport()
    e=E_.transport()
    B_.temp_num+=a
    C_.temp_num+=b
    D_.temp_num+=c
    E_.temp_num+=d

while (B_.temp_num!=0):
    time += 1
    b=B_.transport()
    c=C_.transport()
    d=D_.transport()
    e=E_.transport()
    C_.temp_num+=b
    D_.temp_num+=c
    E_.temp_num+=d

while (C_.temp_num!=0):
    time += 1
    c=C_.transport()
    d=D_.transport()
    e=E_.transport()
    D_.temp_num+=c
    E_.temp_num+=d

while (D_.temp_num!=0):
    time += 1
    d=D_.transport()
    e=E_.transport()
    E_.temp_num+=d

while (E_.temp_num!=0):
    time += 1
    E_.transport()
print(time)

Submission status: Time Limit Exceeded

Solution code:
lst= [int(input()), 0, 0, 0, 0]
moves = [int(input()) for _ in range(5)]

def hoge(lst):
    l1 = [max(x -y , 0) for x, y in zip(lst, moves)]
    l2 = [min(x ,y) for x, y in zip(lst, moves)]
    l1.append(0)
    l2.insert(0,0)
    tmp = [ a + b for a, b in zip(l1, l2)]
    return tmp[0:5]

ret = 0
while sum(lst) > 0:
    lst = hoge(lst)
    ret += 1

print(ret)

Submission status: Time Limit Exceeded

Solution code:
ar = []                                            
raw = raw_input()                                  
ar.append(int(raw))                                
raw = raw_input()                                  
ar.append(int(raw))                                
raw = raw_input()                                  
ar.append(int(raw))                                
raw = raw_input()                                  
ar.append(int(raw))                                
raw = raw_input()                                  
ar.append(int(raw))                                
raw = raw_input()                                  
ar.append(int(raw))                                

total = 0                                          

n = ar[0]                                          
a = ar[1]                                          
b = ar[2]                                          
c = ar[3]                                          
d = ar[4]                                          
e = ar[5]                                          
   
c1 = n                                             
c2 = 0
c3 = 0                                             
c4 = 0                                             
c5 = 0                                             
c6 = 0                                             

i = 0                                              
while True:                                        
    m5 = min(c5,e)                                 
    c6 += m5                                       
    c5 -= m5                                       

    m4 = min(c4,d)                                 
    c5 += m4                                       
    c4 -= m4                                       
         
    m3 = min(c3,c)                                 
    c4 += m3                                       
    c3 -= m3

    m2 = min(c2,b)                                 
    c3 += m2                                       
    c2 -= m2

    m1 = min(c1,a)                                 
    c2 += m1                                       
    c1 -= m1

    #print n, c1, c2, c3, c4, c5, c6
    if c6 == n:
        i += 1                                     
        break                                      
    else:                                          
        i += 1                                     

print i

Submission status: Time Limit Exceeded

Solution code:
import sys


def main():
    input = sys.stdin.readline
    n = int(input())
    nin_list = [int(input()) for _ in range(5)]
    area_list = [n, 0, 0, 0, 0, 0]
    time = 0
    while area_list[5] != n:
        for i in range(4, -1, -1):
            if area_list[i] == 0:
                continue
            move_nin = nin_list[i] if area_list[i] > nin_list[i] else area_list[i]
            area_list[i] -= move_nin
            area_list[i + 1] += move_nin
        time += 1
    print(time)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
memo = [0]*6
count = 0

N, a, b, c, d, e  = [int(input()) for i in range(6)]

memo[0] = N

while True:
  memo[5] = memo[5] + min(e,memo[4])
  memo[4] = memo[4] - min(e,memo[4]) + min(d,memo[3])
  memo[3] = memo[3] - min(d,memo[3]) + min(c,memo[2])
  memo[2] = memo[2] - min(c,memo[2]) + min(b,memo[1])
  memo[1] = memo[1] - min(b,memo[1]) + min(a,memo[0])
  memo[0] = memo[0] - min(a,memo[0])
  count += 1
  if memo[5]==N:
    break

print(count)

Submission status: Time Limit Exceeded

Solution code:
def main():
  n=int(input())
  lst=[int(input()) for i in range(5)]
  l=[0]*5
  l.insert(0,n)
  ans=0
  while l[5]!=n:
    for i in range(5,0,-1):
      if l[i-1]!=0:
        res=min(l[i-1],lst[i-1])
        l[i]+=res
        l[i-1]-=res
    ans+=1
  print(ans)
if __name__=='__main__':
  main()

Submission status: Time Limit Exceeded

Solution code:
N, A, B, C, D, E= [float(input()) for _ in range(6)]
cities = [A, B, C, D, E]
P = [N, 0, 0, 0, 0, 0]
t = 0
while True:
  t += 1
  for i in range(5)[::-1]:
    if P[i] > 0:
      s = P[i] - cities[i]
      if s < 0 :
        P[i+1] += P[i]
        P[i] = 0
      else :
        P[i+1] += cities[i]
        P[i] = s
  if(N <= P[5]):
    break
print(t)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(input()) for i in range(5)]
count = 0
p = [n, 0, 0, 0, 0, 0]
result = p
while(True):
    if result[5] == n:
        print(count)
        break
    else:
        for i, per in enumerate(p[:-1]):
            if per >= a[i]:
                result[i] -= a[i]
                result[i + 1] += a[i]
            elif per > 0 and per < a[i]:
                result[i] -= per
                result[i + 1] += per
    p = result
    count += 1

Submission status: Time Limit Exceeded

Solution code:
memo = [0]*5
count = 0

N, a, b, c, d, e  = [int(input()) for i in range(6)]

memo[0] = N

while True:
  memo[4] = memo[4] - min(e,memo[4]) + min(d,memo[3])
  memo[3] = memo[3] - min(d,memo[3]) + min(c,memo[2])
  memo[2] = memo[2] - min(c,memo[2]) + min(b,memo[1])
  memo[1] = memo[1] - min(b,memo[1]) + min(a,memo[0])
  memo[0] = memo[0] - min(a,memo[0])
  count += 1
  if memo[0] <=0 and memo[1]<=0 and memo[2]<=0 and memo[3]<=0 and memo[4]<=0:
    break

print(count)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=[int(input()) for i in range(5)]
a=s[0]
b=s[1]
c=s[2]
d=s[3]
e=s[4]
p=[n, 0, 0, 0, 0, 0]
t=0
while p[5] != n:
  #to6
  if p[4] >= e:
    p[4] -= e
    to6 = e
  else:
    to6 = p[4]
    p[4] = 0
  p[5] += to6
  #to5
  if p[3] >= d:
    p[3] -= d
    to5 = d
  else:
    to5 = p[3]
    p[3] = 0
  p[4] += to5
  #to4
  if p[2] >= c:
    p[2] -= c
    to4 = c
  else:
    to4 = p[2]
    p[2] = 0
  p[3] += to4
  #to3
  if p[1] >= b:
    p[1] -= b
    to3 = b
  else:
    to3 = p[1]
    p[1] = 0
  p[2] += to3
  #to2
  if p[0] >= a:
    p[0] -= a
    to2 = a
  else:
    to2 = p[0]
    p[0] = 0
  p[1] += to2
  t+=1
print(t)

Submission status: Time Limit Exceeded

Solution code:
import sys
 
N = int(sys.stdin.readline().strip()) 
A = int(sys.stdin.readline().strip())
B = int(sys.stdin.readline().strip())
C = int(sys.stdin.readline().strip())
D = int(sys.stdin.readline().strip())
E = int(sys.stdin.readline().strip())



num = [A,B,C,D,E]
city = [0 for i in range(6)]
city[0] = N


t=0
n = N
while(city[-1]!=N):
    if(city[-2]!=0):
        if(E >= city[-2]):
            city[-1] += city[-2]
            city[-2] = 0
        else:
            city[-1] += E
            city[-2] = city[-2] - E
            
    if(city[-3]!=0):
        if(D >= city[-3]):
            city[-2] += city[-3]
            city[-3] = 0
        else:
            city[-2] += D
            city[-3] = city[-3] - D
            
    if(city[-4]!=0):
        if(C >= city[-4]):
            city[-3] += city[-4]
            city[-4] = 0
        else:
            city[-3] += C
            city[-4] = city[-4] - C
            
    if(city[-5]!=0):
        if(B >= city[-5]):
            city[-4] += city[-5]
            city[-5] = 0
        else:
            city[-4] += B
            city[-5] = city[-5] - B

    if(city[-6]!=0):
        if(A >= city[-6]):
            city[-5] += city[-6]
            city[-6] = 0
        else:
            city[-5] += A
            city[-6] = city[-6] - A
            
    
    t+=1
            
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())

sub = [a,b,c,d,e]
city = [N,0,0,0,0,0]
time = 0

def sub_h(h, num):
    if h - num <= 0:
        return 0
    else:
        return h-num

def add_h(h, num):
    return h+num

while not (city[0] == 0 and city[1] == 0 and city[2] == 0 and city[3] == 0 and city[4] == 0):
    time+=1
    city_copy = city.copy()
    for i in range(len(sub)):
        if city_copy[i] == 0:
            trans = 0
        elif city_copy[i] - sub[i] <= 0:
            trans = city_copy[i]
        else:
            trans = sub[i]
        city[i] -= trans
        city[i+1] += trans
print(time)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
l = [int(input()) for i in range(5)]
ans = [0]*6
ans[0] = N
ans_num = 0
while(ans[5]!=N):
  tmp = [0]*6
  ans_num+=1
  for i in range(5):
    ans_tmp = ans[i]
    if ans_tmp!=0:
      if ans_tmp<=l[i]:
        tmp[i+1] = ans_tmp
        ans[i]=0
      else:
        tmp[i+1] = l[i]
        ans[i]-=l[i]
  for i in range(6):
    ans[i]+=tmp[i]
print(ans_num)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
inputs = [0,0,0,0,0]
inputs[0] = int(input())

inputs[1] = int(input())

inputs[2] = int(input())

inputs[3] = int(input())

inputs[4] = int(input())

posi = [n,0,0,0,0,0]

it = 0
while True:
	for i in range(1,6):
		j = 5 - i
		if posi[j] >= inputs[j]:
			posi[j] = posi[j] - inputs[j]
			posi[j+1] = posi[j+1] + inputs[j]
		else:
			posi[j+1] = posi[j+1] + posi[j]
			posi[j] = 0
	#print(posi)
	it = it + 1
	if posi[5] == n:
		break
print(it)

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())

status = [n, 0, 0, 0, 0, 0]

for i in range(10000000000):
    status[5] += min(status[4], e)
    status[4] -= min(status[4], e)

    status[4] += min(status[3], d)
    status[3] -= min(status[3], d)

    status[3] += min(status[2], c)
    status[2] -= min(status[2], c)

    status[2] += min(status[1], b)
    status[1] -= min(status[1], b)

    status[1] += min(status[0], a)
    status[0] -= min(status[0], a)

#    print(status)

    if status == [0, 0, 0, 0, 0, n]:
        #        print('finish!')
        print(i+1)
        exit()

# if status == [n, 0, 0, 0, 0, 0]:
#    print('ittti')
# print(status)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A,B,C,D,E = [int(input()) for _ in range(5)]
S = [0] * 5
S[0] = N
count = 0
while True :
    if S[4] > 0 :
        if S[4] - E >= 0 :
            S[4] =  S[4] - E
        else :
            S[4] = 0
    if S[3] > 0 :
        if S[3] - D >= 0:
            S[3] = S[3] - D
            S[4] = S[4] + D
        else :
            S[4] = S[4] + S[3]
            S[3] = 0
    if S[2] > 0:
        if S[2] - C >= 0:
            S[2] = S[2] - C
            S[3] = S[3] + C
        else:
            S[3] = S[3] + S[2]
            S[2] = 0
    if S[1] > 0:
        if S[1] - B >= 0:
            S[1] = S[1] - B
            S[2] = S[2] + B
        else:
            S[2] = S[2] + S[1]
            S[1] = 0
    if S[0] > 0:
        if S[0] - A >= 0:
            S[0] = S[0] - A
            S[1] = S[1] + A
        else:
            S[1] = S[1] + S[0]
            S[0] = 0

    #print(S)
    count += 1
    if S[0] == 0 and S[1] == 0 and S[2] == 0 and S[3] == 0 and S[4] == 0 :
        break

print(count)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

N = int(stdin.readline().rstrip())
max_ride = [int(stdin.readline().rstrip()) for _ in range(5)]

shima = [N, 0, 0, 0, 0, 0]
shima_next = [0, 0, 0, 0, 0, 0]

res_time = 0
while(shima[5] != N):
    res_time += 1
    for i in range(5, 0, -1):
        if shima[i-1] == 0:
            continue

        if shima[i-1] > max_ride[i-1]:
            shima_next[i-1] = shima[i-1] - max_ride[i-1]
            shima_next[i] += max_ride[i-1]
        else:
            shima_next[i-1] = 0
            shima_next[i] += shima[i-1]
    
    shima = shima_next[:]

print(res_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())

class Transporter():
    def __init__(self, cap_out, temp=0):
        self.temp_num = temp
        self.cap_out = cap_out

    def transport(self):
        if self.temp_num < self.cap_out:
            num = self.temp_num
            self.temp_num = 0
            return num
        else:
            self.temp_num -= self.cap_out
            return self.cap_out

A_ = Transporter(A, temp=N)
B_ = Transporter(B)
C_ = Transporter(C)
D_ = Transporter(D)
E_ = Transporter(E)

time = 0
while (A_.temp_num!=0 or B_.temp_num!=0 or C_.temp_num!=0 or D_.temp_num!=0 or E_.temp_num!=0):
    time += 1
    a=A_.transport()
    b=B_.transport()
    c=C_.transport()
    d=D_.transport()
    e=E_.transport()
    B_.temp_num+=a
    C_.temp_num+=b
    D_.temp_num+=c
    E_.temp_num+=d

print(time)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
li = [int(input()) for _ in range(5)]
li.insert(0, 0)
#print(li)
plot = [n, 0, 0, 0, 0, 0]
count = 0
"""for i in range(1, 5):
    print(i)"""
time = 0
while plot[5] != n:
  for i in range(5, 0, -1):
    #print(i)
    if plot[i-1] - li[i] >= 0:
      plot[i-1] -= li[i]
      plot[i] += li[i]
    else:
      plot[i] += plot[i-1]
      plot[i-1] = 0
    #print(plot, time)
    count += 1
  #if count >= 100:
      #break
  time += 1

print(time)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=[]
for i in range(5):
    A.append(int(input()))
B=[N,0,0,0,0,0]
j=0
while B[5]!=N:
        C=[]
        C.append(B[0]-min(B[0],A[0]))
        for i in range(4):
             C.append(B[i+1]+min(B[i],A[i])-min(B[i+1],A[i+1]))
        C.append(B[5]+min(B[4],A[4]))
        B=C
        j=j+1
print(j)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

n = int(stdin.readline().rstrip())
data = []

for i in range(5):
    data.append(int(stdin.readline().rstrip()))

t = 0
town = [n, 0, 0, 0, 0, 0]

while town[5] < n:
    if town[4] > 0:
        if data[4] > town[4]:
            town[5] += town[4]
            town[4] = 0
        else:
            town[5] += data[4]
            town[4] -= data[4]
    if town[3] > 0:
        if data[3] > town[3]:
            town[4] += town[3]
            town[3] = 0
        else:
            town[4] += data[3]
            town[3] -= data[3]
    if town[2] > 0:
        if data[2] > town[2]:
            town[3] += town[2]
            town[2] = 0
        else:
            town[3] += data[2]
            town[2] -= data[2]
    if town[1] > 0:
        if data[1] > town[1]:
            town[2] += town[1]
            town[1] = 0
        else:
            town[2] += data[1]
            town[1] -= data[1]
    if town[0] > 0:
        if data[0] > town[0]:
            town[1] += town[0]
            town[0] = 0
        else:
            town[1] += data[0]
            town[0] -= data[0]
    t += 1

print(t)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
mt = []
mt.append(int(input()))
mt.append(int(input()))
mt.append(int(input()))
mt.append(int(input()))
mt.append(int(input()))

nums = [0] * 6

time = 0
nums[0] = n
next_nums = nums[:]
while nums[5] < n:
  for i in range(5):
    d = min(nums[i], mt[i])
    next_nums[i] -= d
    next_nums[i + 1] += d
  time += 1
  for i in range(6):
    nums[i] = next_nums[i]

print(time)