Problem: There are N+1 towns. The i-th town is being attacked by A_i monsters.  We have N heroes. The i-th hero can defeat monsters attacking the i-th or (i+1)-th town, for a total of at most B_i monsters.  What is the maximum total number of monsters the heroes can cooperate to defeat?

Submission attempts (in order):
# -*- coding: utf-8 -*-
import sys
import itertools

#w=input()
from operator import itemgetter
from sys import stdin


N=3
M=3
i=0
j=0
k=0
ans=0


N=int(input())
#A=int(input())
#B=int(input())
#print(N)
monster_list=list(map(int, input().split(" ")))
beat_list=list(map(int, input().split(" ")))

#print(beat_list)

for i in reversed(range(N+1)):
 print(i)
 print(monster_list)
 print(beat_list)
 if i >=1:
    if beat_list[i-1]<monster_list[i]:
        ans=ans+beat_list[i-1]
        beat_list[i-1]=0
    else:
        beat_list[i-1]=beat_list[i-1]-monster_list[i]
        ans=ans+monster_list[i]
        monster_list[i]=0
        if beat_list[i-1]>=monster_list[i-1]:
            ans=ans+monster_list[i-1]

        else:
            ans=ans+beat_list[i-1]
            monster_list[i-1]=monster_list[i-1]-beat_list[i-1]

 # else:
 
 

 #     else:
 #         ans=ans+beat_list[i]
print(ans)

"1行1つの整数を入力を取得し、整数と取得する"


#number_list=list(map(int, input().split(" ")))
#print(number_list)
"12 21 332 とか入力する時に使う"
"1行に複数の整数の入力を取得し、整数として扱う"

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''








#print(type(brray[0][0]))
#print(brray)

"列数に関して自由度の高いint型の値を入力するタイプの行列"


'''
table = [[int(i) for i in input().split()] for m in range(m)]

print(type(N))
print(N)
print(type(M))
print(M)

print(type(table))
print(table)
'''




#s=input()

#print(a[0])
#print([a])















#a= stdin.readline().rstrip()
#print(a.upper())
"aという変数に入っているものを大文字にして出力"





#a=[[int(i) for i in 1.strip()]for 1 in sys.stdin]
#a = [[int(c) for c in l.strip()] for l in sys.stdin]]
#print(a)



# -*- coding: utf-8 -*-
import sys
import itertools

#w=input()
from operator import itemgetter
from sys import stdin


N=3
M=3
i=0
j=0
k=0
ans=0


N=int(input())
#A=int(input())
#B=int(input())
#print(N)
monster_list=list(map(int, input().split(" ")))
beat_list=list(map(int, input().split(" ")))

#print(beat_list)

for i in reversed(range(N+1)):
 #print(i)
 
 #print(beat_list)
 if i >=1:
    if beat_list[i-1]<monster_list[i]:
        ans=ans+beat_list[i-1]
        beat_list[i-1]=0
        monster_list[i]=monster_list[i]-beat_list[i-1]
    else:
        beat_list[i-1]=beat_list[i-1]-monster_list[i]
        ans=ans+monster_list[i]
        monster_list[i]=0
        if beat_list[i-1]>=monster_list[i-1]:
            ans=ans+monster_list[i-1]
            monster_list[i-1]=0
        else:
            ans=ans+beat_list[i-1]
            monster_list[i-1]=monster_list[i-1]-beat_list[i-1]
            beat_list[i-1]=0

 # else:
 
 

 #     else:
 #         ans=ans+beat_list[i]
print(ans)

"1行1つの整数を入力を取得し、整数と取得する"


#number_list=list(map(int, input().split(" ")))
#print(number_list)
"12 21 332 とか入力する時に使う"
"1行に複数の整数の入力を取得し、整数として扱う"

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''








#print(type(brray[0][0]))
#print(brray)

"列数に関して自由度の高いint型の値を入力するタイプの行列"


'''
table = [[int(i) for i in input().split()] for m in range(m)]

print(type(N))
print(N)
print(type(M))
print(M)

print(type(table))
print(table)
'''




#s=input()

#print(a[0])
#print([a])















#a= stdin.readline().rstrip()
#print(a.upper())
"aという変数に入っているものを大文字にして出力"





#a=[[int(i) for i in 1.strip()]for 1 in sys.stdin]
#a = [[int(c) for c in l.strip()] for l in sys.stdin]]
#print(a)



Verdicts: Runtime Error

Accepted