Problem:


Score : 300 points

Problem Statement

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?

Constraints

All values in input are integers.

1 \leq N \leq 10^5

1 \leq A_i \leq 10^9

1 \leq B_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_{N+1}
B_1 B_2 ... B_N

Output

Print the maximum total number of monsters the heroes can defeat.

Sample Input 1

2
3 5 2
4 5

Sample Output 1

9

If the heroes choose the monsters to defeat as follows, they can defeat nine monsters in total, which is the maximum result.

The first hero defeats two monsters attacking the first town and two monsters attacking the second town.

The second hero defeats three monsters attacking the second town and two monsters attacking the third town.

Sample Input 2

3
5 6 3 8
5 100 8

Sample Output 2

22

Sample Input 3

2
100 1 1
1 100

Sample Output 3

3



Sample input:
2
3 5 2
4 5


Sample output:
9

Submission status: Wrong Answer

Solution code:
n = int(input())
b = list(map(int,input().split()))
a = list(map(int,input().split()))

ans = 0

for i in reversed(range(n)):
    if b[i+1] - a[i] >= 0:
        b[i+1] -= a[i]
        ans += a[i]
    else:
        a[i] -= b[i+1]
        ans += b[i+1]
        if b[i] - a[i] >= 0:
            b[i] -= a[i]
            ans += a[i]
        else:
            ans += b[i]
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
total = 0

for i in range(1,N) :
    if A[i] >= B[i]:
        total += B[i]
    elif A[i] + A[i+1] >= B[i]:
        total += B[i]
        A[i+1] = A[i] + A[i+1] - B[i]
    elif A[i] + A[i+1] < B[i] :
        total += A[i] + A[i+1]
        A[i+1] = 0

print(total)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
total = 0

for i in range(1,N) :
    if A[i] >= B[i]:
        total += B[0]
    elif A[i] + A[i+1] >= B[i]:
        total += B[i]
        A[i+1] = A[i] + A[i+1] - B[i]
    elif A[i] + A[i+1] < B[i] :
        total += A[i] + A[i+1]
        A[i+1] = 0

print(total)

Submission status: Wrong Answer

Solution code:
n = int(input())
s1 = input().split()
lst1 = [int(i) for i in s1]
s2 = input().split()
lst2 = [int(i) for i in s2]
lst2.append(0)
sum = 0
for i in range(n):
    if (lst1[i] <= lst2[i]):
        lst2[i+1] += (lst2[i] - lst1[i])
        sum += lst1[i]
    else:
        sum += lst2[i]
if lst1[n] <= lst2[n]:
    sum += lst1[n]
else:
    sum += lst2[n]
print(sum)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans = 0
for i in range(n):
    if a[i] >= b[i]:
        ans += b[i]
    else:
        ans += a[i]
        b[i] -= a[i]
        if a[i+1] >= b[i]:
            ans += b[i]
            a[i+1] -= b[i]
        else:
            ans += a[i+1]
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

E = 0

for i in range(N-1,-1,-1):#N-0まで
	for j in range(i+1,i-1,-1):#i+1-iまで
		if B[i] - A[j] > 0:
			E += A[j]
			B[i] = B[i] - A[j]
			A[j] = 0
		if B[i] - A[j] <= 0:
			E += B[i]
			B[i] = 0
			break
			
print(E)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

E = 0

for i in range(N-1,-1,-1):#N-0まで
	for j in range(i+1,i-1,-1):#i+1-iまで
		if B[i] - A[j] > 0:
			E += A[j]
			B[i] = B[i] - A[j]
			A[j] = 0
			print(E)
		if B[i] - A[j] <= 0:
			E += B[i]
			B[i] = 0
			break
			
print(E)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

E = 0

for i in range(N-1,-1,-1):
	for j in range(i+1,i-1,-1):
		if B[i] - A[j] > 0:
			E += A[j]
			B[i] = B[i] - A[j]
			A[j] = 0
		if B[i] - A[j] <= 0:
			E += B[i]
			B[i] = 0
			break
			
print(E)

Submission status: Wrong Answer

Solution code:
n = int(input())
*a, = map(int, input().split())
*b, = map(int, input().split())
count = 0
for i in range(n):
    if b[i] > a[i]:
        b[i] -= a[i]
        count += a[i]
    else:
        count += b[i]
        continue
    if b[i] > a[i + 1]:
        count += a[i + 1]
    else:
        count += b[i]
        a[i + 1] - b[i]

print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
*a, = map(int, input().split())
*b, = map(int, input().split())
count = 0
for i in range(n):
    if b[i] >= a[i]:
        count += a[i]
        b[i] -= a[i]
    else:
        count += b[i]
        continue
    if b[i] >= a[i+1]:
        count += a[i+1]
    else:
        a[i+1] -= b[i]
        count += b[i]

print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
count = 0
for i in range(N):
    judge = A[i] - B[i]
    if judge <= 0:
        count += A[i]
    else:
        count += B[i]

    if judge < 0:
        A[i+1] += judge
        if A[i+1] < 0:
            A[i+1] = 0
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
B.append(0)

sup = 0
count = 0
for i in range(len(B)):
	b = B[i]
	m = A[i]
	if m - sup >=  b:
		count += sup + b
		sup = 0
	elif m-sup < b:
		count += m
		sup = b - (m - sup)

print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
B.append(0)

sup = 0
count = 0
for i in range(len(B)):
	b = B[i]
	m = A[i]
	if m - sup >=  b:
		count += sup + b
		sup = 0
	elif m-sup < b:
		count += m
		sup = b-(m-sup)

print(count)

Submission status: Wrong Answer

Solution code:
def main():

    N = int(input())
    A = [int(x) for x in input().split()]
    B = [int(x) for x in input().split()]
    total = 0
    cnt = [0] * (N + 1)
    r = [0] * (N + 1)
    cnt[0] = min(B[0], A[0])
    total += cnt[0]
    r[0] = 0
    for i in range(1, N):
        r[i] = max(B[i - 1] + r[i - 1] - A[i - 1], 0)
        if r[i] >= 0:
            cnt[i] = min(B[i] + r[i], A[i])
            # print(cnt[i])
            total += cnt[i]
        else:
            cnt[i] = min(B[i], A[i])
            total += cnt[i]
    r[N] = B[N - 1] + r[N - 1] - A[N - 1]
    if r[N] >= 0:
        cnt[N] = min(r[N], A[N])
        total += cnt[N]
    else:
        total += 0
    print(total)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
    
ans=0

for i in range(0,N+1):
    A[i]=int(A[i])
for i in range(0,N):
    B[i]=int(B[i])

for i in range(0,N):
    if A[i]-B[i]>=0:
        ans+=B[i]
    elif A[i]-B[i]<0:
        if A[i+1]-(B[i]-A[i])<0:
            ans+=A[i]+A[i+1]
            A[i+1]=0
        else :
            ans+=B[i]
        
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
monsters = list(map(int,input().split()))
savers = list(map(int,input().split()))

s = 0
prev_saver = 0
for monster, saver in zip(monsters[:n], savers):
    if monster > prev_saver+saver:
        s += prev_saver+saver
        prev_saver = 0
    elif monster > prev_saver:
        s += monster
        prev_saver = saver + prev_saver - monster
    else:
        s += monster
        prev_saver = saver - min(monster-prev_saver,0)
print(s + min(monsters[-1], prev_saver))

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
counter=0

for i in range(N):
    if A[i]<=B[i]:
        B[i]-=A[i]
        counter+=A[i]
        A[i]=0
    elif B[i]<A[i]:
        counter+=B[i]
        B[i]=0
        A[i]-=B[i]

    if A[i+1]<=B[i]:
        B[i]-=A[i+1]
        counter+=A[i+1]
        A[i+1]=0
    elif B[i]<A[i+1]:
        counter+=B[i]
        B[i]=0
        A[i+1]-=B[i]

print(counter)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
num = 0
zan = 0
for i in range(N):
    if A[i] <= B[i]:
        zan = B[i] - A[i]
        num += A[i]
        if zan >= A[i + 1]:
            num += A[i + 1]
            zan = 0
        else:
            num += zan
            zan = 0
    else:
        num += B[i]
        zan = 0

#num += min(A[N], zan)

print(num)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
num = 0
zan = 0
for i in range(N):
    if A[i] <= B[i]:
        zan = B[i] - A[i]
        num += A[i]
        if zan >= A[i + 1]:
            num += A[i + 1]
            zan = 0
        else:
            num += zan
            zan = 0
    else:
        num += B[i]
        zan = 0

num += min(A[N], zan)

print(num)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
num = 0
zan = 0
for i in range(N):
    if A[i] <= B[i]:
        zan = B[i] - A[i]
        num += A[i]
        if zan >= A[i + 1]:
            num += A[i + 1]
        else:
            num += zan
    else:
        num += B[i]
num += min(A[N], zan)

print(num)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
num = 0
zan = 0
for i in range(N):
    if A[i] <= B[i]:
        zan = B[i] - A[i]
        num += A[i]
        if zan >= A[i + 1]:
            num += A[i + 1]
        else:
            num += zan
    else:
        num += B[i]
print(num)

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
a = map(int, raw_input().split())
b = map(int, raw_input().split())
m = 0
for i in xrange(n):
  p = max(a[i] - b[i], 0)
  a[i] = a[i] - p
  c = b[i] - p
  q = max(a[i+1] - c, 0) 
  a[i+1] = a[i+1] - q
  m += p + q
print m

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = 0
q = 0
r = 0
B.append(0)
for i in range(N+1):
    r = B[i]+q
    q = r-A[i] if A[i]<r else 0
    ans += A[i] if A[i]<r else r
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = 0

for i in range(n):
  if a[i] + a[i+1] <= b[i]:
    ans += a[i] + a[i+1]
  else:
    ans += b[i]
    
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
num = 0
zan1 = 0
zan2 = 0
for i in range(N):
    if A[i] <= B[i]:
        zan1 = B[i] - A[i]
        num += A[i]
        if zan1 >= A[i + 1]:
            zan2 = zan1 - A[i + 1]
            num += A[i+1]
        else:
            num += zan1
    else:
        num += B[i]

print(num)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
num = 0
zan1 = 0
zan2 = 0
for i in range(N):
    if A[i] < B[i]:
        zan1 = B[i] - A[i]
        num += A[i]
        if zan1 > A[i + 1]:
            zan2 = zan1 - A[i + 1]
            num += A[i+1]
        else:
            num += zan1
    else:
        num += B[i]

print(num)

Submission status: Wrong Answer

Solution code:
n = int(input())
a_list = list(map(int,input().split()))
b_list = list(map(int,input().split()))

zan = 0
ans = 0
for i in range(n):
    temp = b_list[i] + zan
    s = a_list[i]
    if s >= temp:
        ans += temp
    elif s < temp and s >= zan:
        ans += s
        zan = temp - s        
    else:
        ans += s
        zan = b_list[i]

if zan > a_list[n]:
    ans += a_list[n]
else:
    ans += zan
        
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a_list = list(map(int,input().split()))
b_list = list(map(int,input().split()))

zan = 0
ans = 0
for i in range(n):
    temp = b_list[i] + zan
    s = a_list[i]
    if s >= temp:
        ans += temp
    else:
        ans += s
        zan = temp - s

if zan > a_list[n]:
    ans += a_list[n]
else:
    ans += zan
        
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
for i in range(n):
	if a[i] > b[i]:
		ans += b[i]
		b[i] = 0 
	else:
		b[i] -= a[i] 
		ans += a[i]
		if a[i+1] > b[i]:
			ans += b[i]
			b[i] = 0
		else:
			b[i] -= a[i+1]
			ans += a[i+1]
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
count = 0
X = []
X.append(0)
for i in range(N):
    count += min(A[i], - X[i] + B[i])
    X.append(min(A[i] + X[i] - B[i], 0))

count += min(A[N], - X[N-1])
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
count = 0
X = 0
for i in range(N):
    count += min(A[i], - X + B[i])
    X = min(A[i] + X - B[i], 0)

count += min(A[N], - X)
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
B.append(0)
B.append(0)
cnt = 0
for i in range(N+1):
    if A[i]-B[i]==0:
        cnt += B[i]
        
    elif A[i]-B[i]>=0:
        cnt += B[i]
        
    elif A[i]-B[i]<=0:
        cnt += A[i]
        if B[i+1] + B[i]-A[i] <= A[i]:
            B[i+1] += B[i]-A[i]
        else:
            B[i+1] == A[i+1]
    
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
B.append(0)
B.append(0)
cnt = 0
for i in range(N+1):
    if A[i]-B[i]==0:
        cnt += B[i]
        
    elif A[i]-B[i]>=0:
        cnt += B[i]
        
    elif A[i]-B[i]<=0:
        cnt += A[i]
        B[i+1] += B[i]-A[i]
        
    
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
Alist = list(map(int, input().split()))
Blist = list(map(int, input().split()))
beforeN = sum(Alist)
for i in range(N - 1, -1, -1):
    rest_power = Blist[i] - Alist[i + 1]
    if rest_power > 0:
        Alist[i + 1] = 0
        last_power = Alist[i] - rest_power
        if last_power <= 0:
            Alist[i] = 0
        else:
            Alist[i] = Alist[i] - rest_power
    else:
        Alist[i + 1] = Alist[i + 1] - Blist[i]
        continue
ans = beforeN - sum(Alist)
print(Alist)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
AL = list(map(int,input().split()))
BL = list(map(int,input().split()))
ans = 0
for i in range(n):
    if BL[i] <= AL[i]:
        ans += BL[i]
    elif BL[i] > AL[i] and BL[i] <= AL[i]+AL[i+1]:
        ans += BL[i]
        AL[i+1] = AL[i+1] - AL[i] - BL[i]
    else:
        ans += AL[i]+AL[i+1]
        AL[i+1] = 0
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

cnt = 0
for i in range(n):
    if b[i]>=a[i]:
        cnt += a[i]
        b[i] -= a[i]
        a[i+1] -= min(b[i],a[i+1])
        cnt += min(b[i],a[i+1])
    
    else:
        cnt += b[i]
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
monsters = list(map(int, input().split()))
heroes = list(map(int, input().split()))

cnt = 0
for i in range(n):
  if heroes[i] <= monsters[i]:
    cnt += heroes[i]
  else:
    cnt += monsters[i]
    heroes[i] -= monsters[i]
    if heroes[i] <= monsters[i]:
      cnt += heroes[i]
      monsters[i+1] -= heroes[i]
    else:
      cnt += monsters[i+1]
      monsters[i+1] = 0
    
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
b.append(0)
result_L = []
yoryoku_L = [0]

for val in range(n+1):
    yoryoku = yoryoku_L[val] + b[val] - a[val]
    if yoryoku >= 0:
        result = a[val]
        yoryoku_L.append(yoryoku)
        result_L.append(result)
    else:
        result = b[val] + yoryoku_L[val]
        yoryoku_L.append(0)
        result_L.append(result)


print(sum(result_L))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

M = 0

for i in range(N):
  if B[N-1-i] < A[N-i]:
    M += B[N-1-i]
    B[N-1-i] = 0
  elif B[N-1-i] >= A[N-i] and B[N-1-i] < A[N-i] + A[N-i-1]:
    M += B[N-1-i]
    A[N-i-1] -= B[N-1-i] - A[N-i]
    B[N-1-i] = 0
  elif B[N-1-i] >= A[N-i] + A[N-1-i]:
    M += A[N-i] + A[N-1-i]
    A[N-i] = 0

print(M)

Submission status: Wrong Answer

Solution code:
n = int(input())
a, b = [list(map(int, input().split())) for _ in range(2)]
bSum = 0
for i in range(n):
    if a[i] >= b[i]:
        bSum += b[i]
        a[i] -= b[i]
        b[i] = 0
    elif a[i] + a[i + 1] >= b[i]:
        bSum += b[i]
        a[i] = 0
        a[i + 1] -= b[i] - a[i]
    elif a[i] + a[i + 1] <= b[i]:
        bSum += a[i] + a[i + 1]
        a[i + 1] = 0

print(bSum)

Submission status: Wrong Answer

Solution code:
n = int(input())
monsters = list(map(int, input().split()))
heroes = list(map(int, input().split()))

cnt = 0
remain = 0
for i in range(n):
  if heroes[i] + remain < monsters[i]:
    cnt += heroes[i] + remain
    remain = 0
  else:
    cnt += monsters[i]
    remain = heroes[i] + remain - monsters[i]
    if i == n-1:
      cnt += min(remain, monsters[i+1])
    
print(cnt)

Submission status: Wrong Answer

Solution code:
while True:
    try:
        N = int(input())
        A = list(map(int, input().split()))
        B = list(map(int, input().split()))
        
        tmp = min(A[0], B[0])
        B[0] = max(B[0] - A[0], 0)
        A[0] = tmp
        for i in range(1, N):
            tmp = min(A[i], B[i-1] + B[i])
            B[i] = max(B[i-1] + B[i] - A[i], 0)
            A[i] = tmp
            
        A[N] = min(A[N], B[N-1])
        print(sum(A))
    except:
        break

Submission status: Wrong Answer

Solution code:
while True:
    try:
        N = int(input())
        A = list(map(int, input().split()))
        B = list(map(int, input().split()))
        carry = 0
        R = []
        for i in range(N):
            R.append(max(A[i] - B[i] - carry, 0))
            carry = max(B[i] + carry - A[i], 0)
        R.append(max(A[i+1] - carry, 0))
        print(sum(A) - sum(R))
    except:
        break

Submission status: Wrong Answer

Solution code:

    
import sys

if sys.platform =='ios':
	sys.stdin=open('input_file.txt')
	
n=int(input())
l1=list(map(int,input().split()))
l2=list(map(int,input().split()))

stc=0
cnt=0

for i in range(n):
	if stc+l2[i]-l1[i]>0:
		stc=stc+l2[i]-l1[i]
		cnt+=l1[i]
	else:
		cnt+=stc+l2[i]
		stc=0
		
	 
cnt+=min(stc,l1[n])


print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(i) for i in input().split(' ')]
B = [int(i) for i in input().split(' ')]
totalB = sum(B)

for i in range(N):
    if i == 0:
        B[i] = B[i] - A[i]
        if B[i]<0:
            B[i] = 0
    else:
        A[i] = A[i] - B[i-1]
        B[i-1] = 0
        if A[i] < 0:
            B[i-1] = abs(A[i])
            A[i] = 0
            
        B[i] = B[i] - A[i]


B[N-1] = B[N-1] - A[N]
if B[N-1] < 0:
    B[N-1] = 0

print(totalB - sum(B))

Submission status: Wrong Answer

Solution code:
def check():
    N = int(input())
    A = [int(i) for i in input().split(' ')]
    B = [int(i) for i in input().split(' ')]
    totalB = sum(B)
    
    for i in range(N):
        if i == 0:
            B[i] = B[i] - A[i]
            if B[i]<0:
                B[i] = 0
        else:
            A[i] = A[i] - B[i-1]
            B[i-1] = 0
            if A[i] <= 0:
                B[i-1] = abs(A[i])
                A[i] = 0
                
            B[i] = B[i] - A[i]
    
    if B[N-1] - A[N] >= 0:
        B[N-1] = B[N-1] - A[N]
    else:
        B[N-1] = 0
    
    print(totalB - sum(B))
    
check()

Submission status: Wrong Answer

Solution code:
N = int(input())
a = input().split()
b = input().split()
b.append(0)
b.append(0)
for num in range(N+1):
  a[num] = int(a[num])
  b[num] = int(b[num])
n = 0
for i in range(N+1):
  if a[i] >= b[i]:
    n += b[i]
  else:
    n += a[i]
    b[i+1] += (b[i] - a[i])
print(int(n))

Submission status: Wrong Answer

Solution code:
N = int(input())
a = input().split()
b = input().split()
for l in range(2):
  b.append(0)
for num in range(N+1):
  a[num] = int(a[num])
  b[num] = int(b[num])
n = 0
for i in range(N+1):
  if a[i] >= b[i]:
    n += b[i]
  else:
    n += a[i]
    b[i+1] += (b[i] - a[i])
print(int(n))

Submission status: Wrong Answer

Solution code:
N = int(input())
a = input().split()
b = input().split()
for l in range(2):
  b.append(0)
for num in range(N+1):
  a[num] = int(a[num])
  b[num] = int(b[num])
n = 0
for i in range(N+1):
  if a[i] >= b[i]:
    n += b[i]
  else:
    n += a[i]
    b[i+1] += (b[i] - a[i])
print(n)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = input().split()
b = input().split()
for l in range(2):
  b.append(0)
for num in range(N+1):
  a[num] = int(a[num])
  b[num] = int(b[num])
n = 0
for i in range(N+1):
  if a[i] >= b[i]:
    n += b[i]
  else:
    n += a[i]
    b[i+1] += b[i] - a[i]
print(n)

Submission status: Wrong Answer

Solution code:
# -*- coding:utf8 -*-

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
d = 0
for i,n in enumerate(b):
    c = a[i]
    if n + d >= c:
        ans += c
        d = n - (c - d) if (c - d) >= 0 else n
    else:
        ans += n
        d = 0
l = a[-1]
if l <= d:
    ans += l
else:
    ans += d
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
n = int(sys.stdin.readline())
a = list(map(int, sys.stdin.readline().split()))
b = list(map(int, sys.stdin.readline().split()))
b+=[0,0]

ten = 0
for i in range(n+1):
    m = b[i]-a[i]
    if m > 0:
        ten +=a[i]
        b[i+1]+= m
    else:
        ten +=b[i]
 
print(ten)

Submission status: Wrong Answer

Solution code:
N = int(input())
A_list = [int(i) for i in input().split()]
B_list = [int(i) for i in input().split()]

killed = 0
for i in range(N) :
    brave = B_list[i]
    monster = A_list[i]
    if (brave >= monster) :
        # 殺りきれる場合
        killed += monster
        brave -= monster
        monster = A_list[i+1]
        if (brave >= monster) :
            killed += monster
            brave -= monster
        elif (brave < monster) :
            # 殺りきれない場合
            killed += brave
            monster -= brave # この処理はいる
            A_list[i+1] = monster
            
    elif (brave < monster) :
        # 殺りきれない場合
        killed += brave
        monster -= monster # この処理はいらない

print(killed)

Submission status: Wrong Answer

Solution code:
n=int(input())
A = list(map( int, input().split( )))
B = list(map( int, input().split( )))
#左から順に倒す
C = [0] * (n+1)
#左隣からの応援
ans = 0
for i in range(n):
    C[i+1] = max(B[i]+C[i]-A[i], 0 )
    ans += min(A[i], B[i] + C[i])

ans += min(A[n], C[n])
print(ans)

Submission status: Wrong Answer

Solution code:
N=input()
N=int(N)
A=list(map(int,input().split()))
B=list(map(int,input().split()))
P=0
p1=min(A[0],B[0])
P12=[]

for i in range(N):
    p12=min(A[i+1],B[i]-p1)
    P12.append(p12)
    P+=p12
    if i>=1and i<N-1:
        p1=min(A[i]-P12[i-1],B[i])
    P+=p1
print(P)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
s = 0

for i in range(n):
    if a[i] < 0:
        a[i] = 0
    tmp = b[i] - a[i]
    if tmp <= 0:
        s += b[i]
    else:
        s += a[i]
        if a[i] > 0:
            s += min(a[i+1],tmp)
            a[i+1] -= tmp
        else:
            a[i+1] -= b[i]
            s += b[i]
            
print(s)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

result = 0

for i in range(N):
    
    if B[i] >= A[i]:
        result += A[i]
        B[i] -= A[i]
        A[i] = 0
        
        if B[i] >= A[i+1]:
            result += A[i+1]
            B[i] -= A[i+1]
            A[i+1] = 0
        else:
            result += B[i]
            B[i] = 0
            A[i+1] -= B[i]
        
    else:
        result += B[i]
        B[i] = 0
        A[i] -= B[i]

print(result)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

result = 0

for i in range(N):
    
    if B[i] >= A[i]:
        result += A[i]
        B[i] -= A[i]
        
        if B[i] >= A[i+1]:
            result += A[i+1]
            B[i] -= A[i+1]
        else:
            result += B[i]
            B[i] = 0
            A[i+1] -= B[i]
        
    else:
        result += B[i]
        B[i] = 0
        A[i] -= B[i]

print(result)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

result = 0

for i in range(N):
    
    if B[i] > A[i]:
        result += A[i]
        B[i] -= A[i]
        
        if B[i] > A[i+1]:
            result += A[i+1]
            B[i] -= A[i+1]
        else:
            result += B[i]
            B[i] = 0
            A[i+1] -= B[i]
        
    else:
        result += B[i]
        B[i] = 0
        A[i] -= B[i]

print(result)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

result = 0

for i in range(N):
    
    if B[i] > A[i]:
        result += A[i]
        B[i] -= A[i]
        
        if B[i] > A[i+1]:
            result += A[i+1]
            B[i] -= A[i+1]
        else:
            result += B[i]
            B[i] = 0
        
    else:
        result += B[i]
        B[i] = 0

print(result)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
R = [0]*(N+1)
ans = 0
for i in range(N):
    if B[i] + R[i] < A[i]:
        ans += B[i]+R[i]
    else:
        R[i+1] = B[i]+R[i]-A[i]
        ans += A[i]
if R[N] < A[N]:
    ans += R[N]
else:
    ans += A[N]
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = 0
remain = a[0]

for i in range(n):
    k = b[i] - remain
    if k <= 0:
        ans += b[i]
        remain = a[i+1]
    elif k > 0:
        if k >= a[i+1]:
            ans += remain + a[i+1]
            remain = 0
        elif k < a[i+1]:
            ans = b[i]
            remian = a[i+1] - k

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = 0
remain = a[0]

for i in range(n):
    k = b[i] - remain
    if k <= 0:
        ans += b[i]
        remain = a[i+1]
    elif k > 0:
        if k >= a[i+1]:
            ans += remain + a[i+1]
            remain = 0
        elif k < a[i+1]:
            ans = b[i]
            remian = a[i+1] - k
    print(ans)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = 0
remain = a[0]

for i in range(n):
    k = b[i] - remain
    if k < 0:
        ans += b[i]
        remain = a[i+1]
    elif k >= 0:
        if k >= a[i+1]:
            ans += remain + a[i+1]
            remain = 0
        elif k < a[i+1]:
            ans = b[i]
            remian = a[i+1] - k
        
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
count = 0
left = 0
for i in range(n):
    if b[i] + left - a[i] >= 0:
        count += a[i]
        left = b[i] + left - a[i]
        if left > b[i]:
            left = b[i]
    else:
        count += b[i]
        left = 0

count += min(left, a[n])
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
A_list = [int(i) for i in input().split()]
B_list = [int(i) for i in input().split()]

killed = 0
for i in range(N) :
    brave = B_list[i]
    monster = A_list[i]
    if (brave >= monster) :
        # 殺りきれる場合
        killed += monster
        brave -= monster
        monster = A_list[i+1]
        if (brave >= monster) :
            killed += monster
            brave -= monster
        elif (brave < monster) :
            # 殺りきれない場合
            killed += brave
            monster -= monster # この処理はいる
            
    elif (brave < monster) :
        # 殺りきれない場合
        killed += brave
        monster -= monster # この処理はいらない

print(killed)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
i=0
s=0
while(i<n+1):
	
	s+=a[i]
	i+=1
# print(s)
b=list(map(int,input().split()))
# c=functools.reduce(lambda x,y:x+y,a)
# print(c)
j=n-1
while(j>=0):
	# print(a[j],a[j+1],b[j],a[j]+a[j+1]-b[j])
	a[j]=max(0,a[j]+a[j+1]-b[j])
	j-=1
print(s-a[0])

Submission status: Wrong Answer

Solution code:
a = int(input())
b = list(map(int,input().split()))
c = list(map(int,input().split()))

ans = 0
for i in range(a):
  ans += min(b[i],c[i])
  c[i] -= min(b[i],c[i])
  ans += min(b[i + 1], c[i])

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
As=list(map(int,input().split()))
Bs=list(map(int,input().split()))
Bs.append(0)

ans=0
for i in range(n):
  c=As[i]+As[i+1]
  if c>Bs[i]:
    ans+=Bs[i]
    if Bs[i]>As[i]:
      As[i+1]-=Bs[i]
  else:
    ans+=c
    As[i+1]=0
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
As=list(map(int,input().split()))
Bs=list(map(int,input().split()))
Bs.append(0)

ans=0
nex=0
for i,a in enumerate(As):
  b=Bs[i]+nex
  if b>=a:
    ans+=a
    nex=b-a
  else:
    ans+=b
    nex=0
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0

for i in range(n):
  if a[i] > b[i]:
    ans += b[i]
  else:
    if a[i] + a[i+1] > b[i]:
      ans += b[i]
      a[i+1] -= b[i] - a[i]
    else:
      ans += a[i] + a[i+1]
      
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
B.extend([0,0])
C = [0]*(N+2)
sum = 0
for i in range(N+1):
    if A[i]-B[i]-C[i]>0:
        sum += B[i]+C[i]
    else:
        sum += A[i]
        C[i+1] = B[i]-A[i]+C[i]
print(sum)

Submission status: Wrong Answer

Solution code:
import math
import sys
import numpy as np
from collections import defaultdict, deque, Counter 
from itertools import accumulate, product, permutations,combinations, combinations_with_replacement
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush
from fractions import gcd

max_value = 1000000000
min_value = -1000000000
sys.setrecursionlimit(max_value)

N = int(input())
As = list(map(int,input().split()))
Bs = list(map(int,input().split()))

v = 0
for i in range(N):
    if As[i] >= Bs[i]:
        v += Bs[i]
        Bs[i] = 0
        continue
    else:
        v += As[i]
        Bs[i] -= As[i]
        if As[i+1] >= Bs[i]:
            v += Bs[i]
            Bs[i] = 0
        else:
            v += As[i+1]
            Bs[i] -= As[i+1]
        
print(v)