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())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

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

Submission status: Wrong Answer

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

B=B+[0]
counter = 0
print(B) 
for i in reversed(range(1, N+1)):
    dif = A[i] - B[i]
    if dif > 0:
        B[i] += min(dif, B[i-1])
        B[i-1] -= min(dif, B[i-1]) 
    counter += min(A[i], B[i])
counter += min(A[i-1], B[i-1])    
print(counter)

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-1,-1, -1):
    if b[i] - a[i+1] + left > 0:
        count += a[i+1]
        left = b[i] - a[i+1] + left
        if left > b[i]:
            left = b[i]
    else:
        count += b[i]
        left = 0

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

Submission status: Wrong Answer

Solution code:
import math
import copy
import sys
import numpy as np

# ===FUNCTION===

def getInputNum():
    inputNum = int(input())
    return inputNum

def getInputListInt():
    outputoData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData

def getSomeInputInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputaNum]
        outputDataList.append(inputDataList)

    return outputDataList

# ===CODE===

n = getInputNum()

a = getInputListInt()
b = getInputListInt()

b.append(0)

ans = 0
tmp = 0

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

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
plus=0
for i in range(N):
  if A[i]>=B[i]+plus:
    ans+=B[i]+plus
    plus=0
  else:
    ans+=A[i]
    plus=B[i]+plus-A[i]
if A[N]>=plus:
  ans+=plus
else:
  ans+=A[N]
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
li_A = list(map(int,input().split()))
li_B = list(map(int,input().split()))
cnt = 0
for i in range(n):
    w = li_A[i] + li_A[i+1]
    if w>=li_B[i]:
        cnt += li_B[i]
    else:
        cnt += w
print(cnt)

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):
    a = A[i]
    b = B[i]
    # print(a, b)
    if x < a:  # 持ち越し分では足りない
        count += x
        x = 0
        a = a - x  # a: 残りの敵

        if a <= b:  # 全部倒せる
            count += a
            # 持ち越し分の計算
            x = b - a
        else:
            count += b
    else:  # 持ち越し分でモンスター全部倒した
        count += a
        x = b
    # print(count)

# print('x:', x)
# count += min(x, A[N])
if A[N] >= x:
    count += x
else:
    count += A[N]
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):
    a = A[i]
    b = B[i]
    # print(a, b)
    if x < a:  # 持ち越し分では足りない
        count += x
        x = 0
        a = a - x  # a: 残りの敵

        if a <= b:  # 全部倒せる
            count += a
            # 持ち越し分の計算
            x = b - a
        else:
            count += b
    else:  # 持ち越し分でモンスター全部倒した
        count += a
        x = b
    # print(count)

# print('x:', x)
count += min(x, A[N])
print(count)

Submission status: Wrong Answer

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

# # confirm
# print(A)
# print(B)
# print("-----------------")

# 後ろから最大数倒していけば良い

# other_setting
m_cnt = 0

# exe
for i in range(n-1, -1, -1) : 

    # i+1番目を最大数倒す
    if B[i] <= A[i+1] : 
        m_cnt += B[i]
        # A[i+1] = A[i+1] -B[i] # この処理は必要ない
        B[i] = 0
    else : 
        m_cnt += A[i+1]
        B[i] -= A[i+1]
        
    # i番目を最大数倒す
    if B[i] <= A[i] : 
        m_cnt += B[i]
        A[i] = A[i] -B[i]
        B[i] = 0
    else : 
        m_cnt += A[i]
        B[i] -= A[i]

# # condirm
# print(A)
# print(B)

# output
print(m_cnt)

Submission status: Wrong Answer

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

# # confirm
# print(A)
# print(B)
# print("-----------------")

# 後ろから最大数倒していけば良い

# other_setting
m_cnt = 0

# exe
for i in range(n-1, -1, -1) : 

    # i+1番目を最大数倒す
    if B[i] <= A[i+1] : 
        m_cnt += B[i]
        B[i] = 0
        # A[i+1] = A[i+1] -B[i] # この処理は必要ない
    else : 
        m_cnt += A[i+1]
        B[i] -= A[i+1]
        
    # i番目を最大数倒す
    if B[i] <= A[i] : 
        m_cnt += B[i]
        B[i] = 0
        A[i] = A[i] -B[i]
    else : 
        m_cnt += A[i]
        B[i] -= A[i]

# # condirm
# print(A)
# print(B)

# output
print(m_cnt)

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):
    a = A[i]
    b = B[i]
    # print(a, b)
    if x < a:  # 持ち越し分では足りない
        count += x
        x = 0
        a -= x

        if a <= b:  # 全部倒せる
            count += a
            # 持ち越し分の計算
            x = b - a
        else:
            count += b
    else:  # 持ち越し分でモンスター全部倒した
        count += a
        x = b
    # print(count)

# print('x:', x)
count += min(x, A[N])
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):
    a = A[i]
    b = B[i]
    if x <= a:  # 持ち越し分では足りない
        count += x
        x = 0
        a -= x

        if a <= b:  # 全部倒せる
            count += a
            # 持ち越し分の計算
            x += b - a
        else:
            count += b
    else:  # 持ち越し分でモンスター全部倒した
        count += a
        x = b
    # print(count)

# print('x:', x)
count += min(x, A[N])
print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
cnt=0
rem=0
for i in range(n):
  if a[i]>=rem:
    cnt+=rem
    a[i]=a[i]-rem
  else:
    cnt+=a[i]
    rem=b[i]
    continue
  if a[i]>=b[i]:
    cnt+=b[i]
  else:
    cnt+=a[i]
    rem=b[i]-a[i]
if a[n]>=rem:
  cnt+=rem
else:
  cnt+=a[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()]+[0,0]
c=0
for i in range(n+1):
    if A[i]<=B[i]:
        c+=A[i]
        B[i+1]+=B[i]-A[i]
    else:
        c+=B[i]
print(c)

Submission status: Wrong Answer

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

    if tmp - a[n-i] > 0:
        c[n-i] = a[n-i]

        #tmp_2 = tmp - a[n-i]
    else:
        c[n-i] = tmp
        #tmp_2 = 0

print(sum(c))

Submission status: Wrong Answer

Solution code:
from sys import stdin

N = int(input())
A = input().split()
B = input().split()
for i in range(N+1):
    A[i] = int(A[i])
for i in range(N):
    B[i] = int(B[i])

Ans = 0
yo = 0
chinpo = True
chinchin = True

for i in range(N):
    if chinpo & chinchin:
        Ans += min(A[i],B[i])
        if B[i] > A[i]:
            yo = B[i] - A[i]
            chinpo = False

    elif not chinpo & chinchin:
        if yo >= A[i]:
            Ans += A[i]
            yo = 0
            chinpo = False
            chinchin = False
        else:
            if B[i]+yo >= A[i]:
                Ans += A[i]
                yo = B[i]+yo-A[i]
                chinpo = False
            else:
                Ans += yo
                yo = 0
                chinpo = True
    else:
        chinpo = True
        chinchin = True
        if B[i-1]>= A[i]:
            Ans += A[i]
            yo = B[i-1] - A[i]
            chinpo = False
        else:
            if B[i]+B[i-1] >= A[i]:
                Ans += A[i]
                yo = B[i]+B[i-1]-A[i]
                chinpo = False
            else:
                Ans += B[i]+B[i-1]
                yo = 0


if yo > A[N]:
    Ans += A[N]
else:
    Ans += yo

print(Ans)

Submission status: Wrong Answer

Solution code:

N = int(input())
A = input().split()
B = input().split()
for i in range(N+1):
    A[i] = int(A[i])
for i in range(N):
    B[i] = int(B[i])

Ans = 0
yo = 0
chinpo = True
chinchin = True

for i in range(N):
    if chinpo & chinchin:
        Ans += min(A[i],B[i])
        if B[i] > A[i]:
            yo = B[i] - A[i]
            chinpo = False

    elif not chinpo & chinchin:
        if yo >= A[i]:
            Ans += A[i]
            yo = 0
            chinpo = False
            chinchin = False
        else:
            if B[i]+yo >= A[i]:
                Ans += A[i]
                yo = B[i]+yo-A[i]
                chinpo = False
            else:
                Ans += yo
                yo = 0
                chinpo = True
    else:
        chinpo = True
        chinchin = True

if yo > A[N]:
    Ans += A[N]
else:
    Ans += yo

print(Ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin

N = int(input())
A = input().split()
B = input().split()
for i in range(N+1):
    A[i] = int(A[i])
for i in range(N):
    B[i] = int(B[i])

Ans = 0
yo = 0
chinpo = True
chinchin = True

for i in range(N):
    if chinpo & chinchin:
        Ans += min(A[i],B[i])
        if B[i] > A[i]:
            yo = B[i] - A[i]
            chinpo = False

    elif not chinpo & chinchin:
        if yo >= A[i]:
            Ans += A[i]
            yo = 0
            chinpo = False
            chinchin = False
        else:
            if B[i]+yo >= A[i]:
                Ans += A[i]
                yo = B[i]+yo-A[i]
                chinpo = False
            else:
                Ans += yo
                yo = 0
                chinpo = True

if yo > A[N]:
    Ans += A[N]
else:
    Ans += yo

print(Ans)

Submission status: Wrong Answer

Solution code:

N = int(input())
A = input().split()
B = input().split()
for i in range(N+1):
    A[i] = int(A[i])
for i in range(N):
    B[i] = int(B[i])

Ans = 0
yo = 0
chinpo = True
chinchin = True

for i in range(N):
    if chinpo & chinchin:
        Ans += min(A[i],B[i])
        if B[i] > A[i]:
            yo = B[i] - A[i]
            chinpo = False

    elif not chinpo & chinchin:
        if yo >= A[i]:
            Ans += A[i]
            yo = 0
            chinpo = False
            chinchin = False
        else:
            if B[i]+yo >= A[i]:
                Ans += A[i]
                yo = B[i]+yo-A[i]
                chinpo = False
            else:
                Ans += yo
                yo = 0
                chinpo = True
    else:
        continue

if yo > A[N]:
    Ans += A[N]
else:
    Ans += yo

print(Ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin

N = int(input())
A = input().split()
B = input().split()
for i in range(N+1):
    A[i] = int(A[i])
for i in range(N):
    B[i] = int(B[i])

Ans = 0
yo = 0
chinpo = True

for i in range(N):
    if chinpo:
        Ans += min(A[i],B[i])
        if B[i] > A[i]:
            yo = B[i] - A[i]
            chinpo = False

    else:
        if yo >= A[i]:
            Ans += A[i]
            yo = 0
            chinpo = True
        else:
            if B[i]+yo >= A[i]:
                Ans += A[i]
                yo = B[i]+yo-A[i]
                chinpo = False
            else:
                Ans += yo
                yo = 0
                chinpo = True

if yo > A[N]:
    Ans += A[N]
else:
    Ans += yo

print(Ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:

N = int(input())
A = input().split()
B = input().split()
for i in range(N+1):
    A[i] = int(A[i])
for i in range(N):
    B[i] = int(B[i])

Ans = 0
yo = 0
chinpo = True

for i in range(N):
    if chinpo:
        Ans += min(A[i],B[i])
        if B[i] > A[i]:
            yo = B[i] - A[i]
            chinpo = False
    else:
        if yo >= A[i]:
            Ans += A[i]
            yo = B[i]
            chinpo = False
        else:
            if B[i]+yo >= A[i]:
                Ans += A[i]
                yo = B[i]+yo-A[i]
                chinpo = False
            else:
                Ans += yo
                yo = 0
                chinpo = True

if yo > A[N]:
    Ans += A[N]
else:
    Ans += yo

print(Ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin

N = int(input())
A = input().split()
B = input().split()
for i in range(N+1):
    A[i] = int(A[i])
for i in range(N):
    B[i] = int(B[i])

Ans = 0
yo = 0
chinpo = True

for i in range(N):
    if chinpo:
        Ans += min(A[i],B[i])
        if B[i] > A[i]:
            yo = B[i] - A[i]
            chinpo = False
    else:

        if yo >= A[i]:
            Ans += A[i]
            yo = B[i]
            chinpo = False
        elif B[i]+yo >= A[i]:
            Ans += A[i]
            yo = B[i]+yo-A[i]
            chinpo = False
        else:
            Ans += yo
            yo = 0
            chinpo = True

if yo > A[N]:
    Ans += A[N]
else:
    Ans += yo

print(Ans)

Submission status: Wrong Answer

Solution code:

N = int(input())
A = input().split()
B = input().split()
for i in range(N+1):
    A[i] = int(A[i])
for i in range(N):
    B[i] = int(B[i])

Ans = 0
yo = 0
chinpo = True

for i in range(N):
    if chinpo:
        Ans += min(A[i],B[i])
        if B[i] > A[i]:
            yo = B[i] - A[i]
            chinpo = False
    else:
        chinpo = True
        if yo >= A[i]:
            Ans += A[i]
            yo = B[i]
            chinpo = False
        elif B[i]+yo >= A[i]:
            Ans += A[i]
            yo = B[i]+yo-A[i]
            chinpo = False
        else:
            Ans += yo
            yo = 0

if yo > A[N]:
    Ans += A[N]
else:
    Ans += yo

print(Ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin

N = int(input())
A = input().split()
B = input().split()
for i in range(N+1):
    A[i] = int(A[i])
for i in range(N):
    B[i] = int(B[i])

Ans = 0
yo = 0
chinpo = True

for i in range(N):
    if chinpo:
        Ans += min(A[i],B[i])
        if B[i] > A[i]:
            yo = B[i] - A[i]
            chinpo = False
    else:
        #Ans += min(A[i],B[i]+yo)
        chinpo = True
        if yo >= A[i]:
            Ans += A[i]
            yo = B[i]
            chinpo = False
        elif B[i]+yo >= A[i]:
            Ans += A[i]
            yo = B[i]+B[i-1]-A[i-1]-A[i]
            chinpo = False
        else:
            Ans += yo
            yo = 0

if yo > A[N]:
    Ans += A[N]
else:
    Ans += yo

print(Ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
#＃N = int(input())
#s = input()
#S = []
#for i in range(N):
N = int(input())
A = input().split()
B = input().split()
for i in range(N+1):
    A[i] = int(A[i])
for i in range(N):
    B[i] = int(B[i])

Ans = 0
yo = 0
chinpo = True

for i in range(N):
    if chinpo:
        Ans += min(A[i],B[i])
        if B[i] > A[i]:
            yo = B[i] - A[i]
            chinpo = False
    else:
        #Ans += min(A[i],B[i]+yo)
        chinpo = True
        if yo >= A[i]:
            Ans += A[i]
            yo = B[i]
            chinpo = False
        elif B[i]+yo >= A[i]:
            Ans += A[i]
            yo = B[i]+B[i-1]-A[i-1]
            chinpo = False
        else:
            Ans += yo
            yo = 0

if yo > A[N]:
    Ans += A[N]
else:
    Ans += yo

print(Ans)

Submission status: Wrong Answer

Solution code:

N = int(input())
A = input().split()
B = input().split()
for i in range(N+1):
    A[i] = int(A[i])
for i in range(N):
    B[i] = int(B[i])

Ans = 0
yo = 0
chinpo = True

for i in range(N):
    if chinpo:
        Ans += min(A[i],B[i])
        if B[i] > A[i]:
            yo = B[i] - A[i]
            chinpo = False
    else:
        #Ans += min(A[i],B[i]+yo)
        chinpo = True
        if yo >= A[i]:
            Ans += A[i]
            yo = B[i]
            chinpo = False
        elif B[i]+yo >= A[i]:
            yo = B[i]+B[i-1]-A[i-1]
            chinpo = False

if yo > A[N]:
    Ans += A[N]
else:
    Ans += yo

print(Ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = input().split()
B = input().split()
for i in range(N+1):
    A[i] = int(A[i])
for i in range(N):
    B[i] = int(B[i])

Ans = 0
yo = 0
chinpo = True

for i in range(N-1):
    if chinpo:
        Ans += min(A[i],B[i])
        if B[i] > A[i]:
            yo = B[i] - A[i]
            chinpo = False
    else:
        Ans += min(A[i],B[i]+yo)
        chinpo = True
        if yo >= A[i]:
            yo = B[i]
            chinpo = False
        elif B[i]+yo >= A[i]:
            yo = B[i]+B[i-1]-A[i-1]
            chinpo = False

if not chinpo:
    if B[N-1]+B[N-2]-A[N-2]-A[N-1] >= A[N]:
        Ans += A[N]
    else:
        Ans += B[N-1]+B[N-2]-A[N-2]-A[N-1]

print(Ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = input().split()
B = input().split()
for i in range(N+1):
    A[i] = int(A[i])
for i in range(N):
    B[i] = int(B[i])

Ans = 0
yo = 0
chinpo = True

for i in range(N):
    if chinpo:
        Ans += min(A[i],B[i])
        if B[i] > A[i]:
            yo = B[i] - A[i]
            chinpo = False
    else:
        Ans += min(A[i],B[i]+yo)
        chinpo = True
        if B[i-1]-A[i-1] >= A[i]:
            yo = B[i]
            chinpo = False
        elif B[i]+B[i-1]-A[i-1] >= A[i]:
            yo = B[i]+B[i-1]-A[i-1]
            chinpo = False

if not chinpo:
    if B[N-1]+B[N-2]-A[N-2]-A[N-1] >= A[N]:
        Ans += A[N]
    else:
        Ans += B[N-1]+B[N-2]-A[N-2]-A[N-1]

print(Ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = input().split()
B = input().split()
for i in range(N+1):
    A[i] = int(A[i])
for i in range(N):
    B[i] = int(B[i])

Ans = 0
yo = 0
chinpo = True

for i in range(N):
    if chinpo:
        Ans += min(A[i],B[i])
        if B[i] > A[i]:
            yo = B[i] - A[i]
            chinpo = False
    else:
        Ans += min(A[i],B[i]+B[i-1]-A[i-1])
        chinpo = True
        if B[i-1]-A[i-1] >= A[i]:
            yo = B[i]
            chinpo = False
        elif B[i]+B[i-1]-A[i-1] >= A[i]:
            yo = B[i]+B[i-1]-A[i-1]
            chinpo = False

if not chinpo:
    if B[N-1]+B[N-2]-A[N-2]-A[N-1] >= A[N]:
        Ans += A[N]
    else:
        Ans += B[N-1]+B[N-2]-A[N-2]-A[N-1]

print(Ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = input().split()
B = input().split()
for i in range(N+1):
    A[i] = int(A[i])
for i in range(N):
    B[i] = int(B[i])

Ans = 0
chinpo = True

for i in range(N):
    if chinpo:
        Ans += min(A[i],B[i])
        if B[i] > A[i]:
            chinpo = False
    else:
        Ans += min(A[i],B[i]+B[i-1]-A[i-1])
        chinpo = True
        if B[i]+B[i-1]-A[i-1] >= A[i]:
            chinpo = False
            
if not chinpo:
    if B[N-1]+B[N-2]-A[N-2]-A[N-1] >= A[N]:
        Ans += A[N]
    else:
        Ans += B[N-1]+B[N-2]-A[N-2]-A[N-1]

print(Ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = input().split()
B = input().split()
for i in range(N+1):
    A[i] = int(A[i])
for i in range(N):
    B[i] = int(B[i])

Ans = 0
chinpo = True

for i in range(N):
    if chinpo:
        Ans += min(A[i],B[i])
        if B[i] > A[i]:
            chinpo = False
    else:
        Ans += min(A[i],B[i]+B[i-1]-A[i-1])
        chinpo = True
        if B[i]+B[i-1]-A[i-1] >= A[i]:
            chinpo = False

print(Ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = input().split()
B = input().split()
for i in range(N+1):
    A[i] = int(A[i])
for i in range(N):
    B[i] = int(B[i])

Ans = 0
yo = 0

for i in range(N):
    if B[i] - A[i] + yo <= 0:
        Ans += B[i]
        yo = 0
    else:
        Ans += A[i]
        yo = B[i] - A[i]

if yo+B[N-1] >= A[N-1]+A[N]:
    Ans += A[N-1]+A[N]
else:
    Ans += yo + B[N-1]

print(Ans)

Submission status: Wrong Answer

Solution code:

N = int(input())
A = input().split()
B = input().split()
for i in range(N+1):
    A[i] = int(A[i])
for i in range(N):
    B[i] = int(B[i])

Ans = 0

if (B[0]-A[0] > 0):
    if (B[0]-A[0] < A[1]):
        yojo = B[0]-A[0]
        Ans += A[0]
        chinpo = True
        #A[0]+for以下
    else:
        yojo = B[1]
        Ans += A[0]+A[1]
        chinpo = False
        #A[0]+A[1]+for以下
else:
    yojo = 0
    Ans += B[0]
    chinpo = True
    #B[0]+for以下
kintama=True
oppai = True

for i in range(1, N-1):
    if chinpo & oppai:
        yoB = yojo + B[i]
        if yoB >= A[i]:
            yojo = yoB - A[i]
            Ans += A[i]
            if yojo >= A[i+1]:
                Ans += A[i+1]
                chinpo = False
        else:
            Ans += B[i]
            yojo = 0
    else:
        if chinpo & (not oppai):
            if yojo > A[i]:
                Ans += A[i]
                yojo = B[i]
            else:    
                yoB = yojo + B[i]
                if yoB >= A[i]:
                    yojo = yoB - A[i]
                    Ans += A[i]
                    if yojo >= A[i+1]:
                        Ans += A[i+1]
                        chinpo = False
                else:
                    Ans += B[i]
                    yojo = 0
        if not chinpo:
            if i < N-2:
                yojo = B[i]
                chinpo = True
                oppai = False
            else:
                yojo = B[i]
                kintama = False


#以下A[N-1]とA[N]の処理
if chinpo:
    #if yojo >= A[N-1]:#n-3でFalseのときの処理
    #A[N-1]+A[N]について 比較：yojo + B[N-1]
    if yojo + B[N-1] >= A[N-1]+A[N]:
        Ans += A[N-1]+A[N]
    else:
        Ans += yojo + B[N-1]

elif kintama:
    if B[N-1] >= A[N]:
        Ans += A[N]
    else:
        Ans += B[N-1]

else:
    if yojo + B[N-1] >= A[N]:
        Ans += A[N]
    else:
        Ans += yojo + B[N-1]
    #A[N]のみについて 比較：B[N-2] 
print(Ans)

Submission status: Wrong Answer

Solution code:

N = int(input())
A = input().split()
B = input().split()
for i in range(N+1):
    A[i] = int(A[i])
for i in range(N):
    B[i] = int(B[i])

Ans = 0

if (B[0]-A[0] > 0):
    if (B[0]-A[0] < A[1]):
        yojo = B[0]-A[0]
        Ans += A[0]
        chinpo = True
        #A[0]+for以下
    else:
        yojo = B[1]
        Ans += A[0]+A[1]
        chinpo = False
        #A[0]+A[1]+for以下
else:
    yojo = 0
    Ans += B[0]
    chinpo = True
    #B[0]+for以下
kintama=True

for i in range(1, N-1):
    if chinpo:
        yoB = yojo + B[i]
        if yoB >= A[i]:
            yojo = yoB - A[i]
            Ans += A[i]
            if yojo >= A[i+1]:
                Ans += A[i+1]
                chinpo = False
        else:
            Ans += B[i]
            yojo = 0
    else:
        if i < N-2:
            yojo = B[i]
            chinpo = True
        else:
            yojo = B[i]
            kintama = False


#以下A[N-1]とA[N]の処理
if chinpo:
    #if yojo >= A[N-1]:#n-3でFalseのときの処理
    #A[N-1]+A[N]について 比較：yojo + B[N-1]
    if yojo + B[N-1] >= A[N-1]+A[N]:
        Ans += A[N-1]+A[N]
    else:
        Ans += yojo + B[N-1]

elif kintama:
    if B[N-1] >= A[N]:
        Ans += A[N]
    else:
        Ans += B[N-1]

else:
    if yojo + B[N-1] >= A[N]:
        Ans += A[N]
    else:
        Ans += yojo + B[N-1]
    #A[N]のみについて 比較：B[N-2] 

    

print(Ans)

Submission status: Wrong Answer

Solution code:

N = int(input())
A = input().split()
B = input().split()
for i in range(N+1):
    A[i] = int(A[i])
for i in range(N):
    B[i] = int(B[i])

Ans = 0

if (B[0]-A[0] > 0):
    if (B[0]-A[0] < A[1]):
        yojo = B[0]-A[0]
        Ans += A[0]
        chinpo = True
        #A[0]+for以下
    else:
        yojo = B[1]
        Ans += A[0]+A[1]
        chinpo = False
        #A[0]+A[1]+for以下
else:
    yojo = 0
    Ans += B[0]
    chinpo = True
    #B[0]+for以下

for i in range(1, N-1):
    if chinpo:
        yoB = yojo + B[i]
        if yoB >= A[i]:
            yojo = yoB - A[i]
            Ans += A[i]
            if yojo >= A[i+1]:
                Ans += A[i+1]
                chinpo = False
        else:
            Ans += B[i]
            yojo = 0
    else:
        if i < N-2:
            yojo = B[i]
            chinpo = True
        else:
            yojo = B[i]


#以下A[N-1]とA[N]の処理
if chinpo:
    #if yojo >= A[N-1]:#n-3でFalseのときの処理
    #A[N-1]+A[N]について 比較：yojo + B[N-1]
    if yojo + B[N-1] >= A[N-1]+A[N]:
        Ans += A[N-1]+A[N]
    else:
        Ans += yojo + B[N-1]

else:
    if B[N-1] >= A[N]:
        Ans += A[N]
    else:
        Ans += B[N-1]
    #A[N]のみについて 比較：B[N-2] 

    

print(Ans)

Submission status: Wrong Answer

Solution code:

N = int(input())
A = input().split()
B = input().split()
for i in range(N+1):
    A[i] = int(A[i])
for i in range(N):
    B[i] = int(B[i])

Ans = 0

if (B[0]-A[0] > 0):
    if (B[0]-A[0] < A[1]):
        yojo = B[0]-A[0]
        Ans += A[0]
        chinpo = True
        #A[0]+for以下
    else:
        yojo = B[1]
        Ans += A[0]+A[1]
        chinpo = False
        #A[0]+A[1]+for以下
else:
    yojo = 0
    Ans += B[0]
    chinpo = True
    #B[0]+for以下

for i in range(1, N-1):
    if chinpo:
        yoB = yojo + B[i]
        if yoB >= A[i]:
            yojo = yoB - A[i]
            Ans += A[i]
            if yojo >= A[i+1]:
                Ans += A[i+1]
                chinpo = False
        else:
            Ans += B[i]
            yojo = 0
    else:
        yojo = B[i]
        chinpo = True


#以下A[N-1]とA[N]の処理
if chinpo:
    #A[N-1]+A[N]について 比較：yojo + B[N-1]
    if yojo + B[N-1] >= A[N-1]+A[N]:
        Ans += A[N-1]+A[N]
    else:
        Ans += yojo + B[N-1]

else:
    if B[N-1] >= A[N]:
        Ans += A[N]
    else:
        Ans += B[N-1]
    #A[N]のみについて 比較：B[N-2] 

    

print(Ans)

Submission status: Wrong Answer

Solution code:

N = int(input())
A = input().split()
B = input().split()
for i in range(N+1):
    A[i] = int(A[i])
for i in range(N):
    B[i] = int(B[i])

Ans = 0

if (B[0]-A[0] > 0):
    if (B[0]-A[0] < A[1]):
        yojo = B[0]-A[0]
        Ans += A[0]
        chinpo = True
        #A[0]+for以下
    else:
        yojo = B[1]
        Ans += A[0]+A[1]
        chinpo = False
        #A[0]+A[1]+for以下
else:
    yojo = 0
    Ans += B[0]
    chinpo = True
    #B[0]+for以下

for i in range(1, N-1):
    if chinpo:
        yoB = yojo + B[i]
        if yoB >= A[i]:
            yojo = yoB - A[i]
            Ans += A[i]
            if yojo >= A[i+1]:
                Ans += A[i+1]
                chinpo = False
        else:
            Ans += B[i]
            yojo = 0
    else:
        yojo = B[i]
        chinpo = True


#以下A[N-1]とA[N]の処理
if chinpo:
    #A[N-1]+A[N]について 比較：yojo + B[N-1]
    if yojo + B[N-1] >= A[N-1]+A[N]:
        Ans += A[N-1]+A[N]
    else:
        Ans += yojo + B[N-1]

else:
    if B[N-2] + B[N-1] >= A[N-1]+A[N]:
        Ans += A[N-1]+A[N]
    else:
        Ans += B[N-2] + B[N-1]
    #A[N]のみについて 比較：B[N-2] 

    

print(Ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = input().split()
B = input().split()
for i in range(N+1):
    A[i] = int(A[i])
for i in range(N):
    B[i] = int(B[i])

Ans = 0

if (B[0]-A[0] > 0):
    if (B[0]-A[0] < A[1]):
        yojo = B[0]-A[0]
        Ans += A[0]
        chinpo = True
        #A[0]+for以下
    else:
        yojo = B[1]
        Ans += A[0]+A[1]
        chinpo = False
        #A[0]+A[1]+for以下
else:
    yojo = 0
    Ans += B[0]
    chinpo = True
    #B[0]+for以下

for i in range(1,N-1):
    if chinpo:
        yoB = yojo + B[i]
        if yoB >= A[i]:
            yojo = yoB - A[i]
            Ans += A[i]
            if yojo >= A[i+1]:
                Ans += A[i+1]
                chinpo = False
        else:
            Ans += B[i]
            yojo = 0
    else:
        yojo = B[i]
        chinpo = True

if yojo >= A[N]:
    Ans += A[N]
else:
    if yojo + B[N-1] > A[N]:
        Ans += A[N]
    else:
        Ans += yojo + B[N-1]

print(Ans)

Submission status: Wrong Answer

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

Ans = 0

if B[0]-A[0] > 0:
    yojo = B[0]-A[0]
    Ans += A[0]
    #A[0]+for以下
else:
    yojo = 0
    Ans += B[0]
    #B[0]+for以下

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

if yojo + B[N-1] > A[N-1]:
    Ans += A[N-1]
else:
    Ans += B[N-1]

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

c = 0
d = 0
for i in range(N):
    a = a_list[i]
    b = b_list[i]

    aa = a - d
    if aa < 0:
        c += a
        aa = 0
    else:
        c += d

    if b <= aa:
        c += b
        d = 0
    else:
        c += aa
        d = b - aa

aa = a_list[-1] - d
if aa < 0:
    c += a
    aa = 0
else:
    c += d

print(c)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]

ans = 0
for i in range(n):
    for j in range(2):
        ans += min(b[i], a[i + j])
        b[i] = max(0, b[i] - a[i + j])
        a[i + j] = max(0, a[i + j] - b[i])
        
print(ans)