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())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))
bl.append(0)

mons = 0
b0 = 0

for a, b in zip(al, bl):
    if a >= (b+b0):
        mons += (b+b0)
    else:
        mons += a
        b0 = b-(a-b0)

print(mons)

Submission status: Wrong Answer

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

mons = 0
next = 0

for a, b in zip(al, bl):
    b += next
    next = 0
    if a >= b:
        mons += b
    else:
        mons += a
        next = b - a
print(mons)

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):
    if a[i] >= c[i]:
        ans += c[i]
        a[i] -= c[i]
    else:
        ans += a[i]
        a[i] = 0
        
    if a[i] >= b[i]:
        ans += b[i]
    else:
        ans += a[i]
        c[i+1] = b[i]-a[i]
ans += c[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
for i in range(N, 0, -1):
    ans += min(A[i], B[i - 1])
    B[i - 1] -= min(A[i],B[i - 1])
    ans += min(A[i - 1],B[i - 1])
    B[i - 1] -= min(A[i - 1], B[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()))
Max=0
for i in range(N):
  if A[i]>=B[i]:
    Max+=B[i]
  else:
    B[i]-=A[i]
    if A[i+1]>=B[i]:
      A[i+1]-=B[i]
      Max+=A[i]+B[i]
    else:
      A[i+1]=0
      Max+=(A[i]+A[i+1])
print(Max)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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 B[i] > A[i]:
        ans += A[i]
        if B[i] - A[i] > A[i + 1]:
            ans += A[i + 1]
        else:
            #A[i + 1] -= B[i] - A[i]
            ans += B[i] - A[i]
            A[i + 1] -= B[i] - 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()))

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

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

Submission status: Wrong Answer

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

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):
  if A[i] - B[i] < 0:
    count += A[i]
    B[i] -= A[i]
    if A[i+1] - abs(A[i] - B[i]) < 0:
      count += A[i+1]
      A[i+1] = 0
    else:
      count += B[i]
      A[i+1] -= abs(A[i] - B[i])
  elif A[i] - B[i] == 0:
    count += A[i]
  else:
    count += B[i]
print(count)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import itertools#これは色々使える組み込み関数みたいなやつ
#import math#数学的計算はこれでいける。普通に0.5乗しても計算可能
#w=input()
from operator import itemgetter
from sys import stdin
#input = sys.stdin.readline#こっちの方が入力が早いが使える時に使っていこう
#これもdpで考えるべきだったかも
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(monster_list)
#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:
 #     if beat_list[i]>=monster_list[i]:
 #         ans=ans+monster_list[i]

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

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


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

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
#メモ
for i in number_list:#こっちの方がrage使うより早いらしい
    print(number_list[i-1])

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

'''
x=[]
y=[]
for i in range(N):
    x1, y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)
print(x)
print(y)
"複数行に2数値を入力する形式 x座標とy座標を入力するイメージ"
'''

'''
mixlist=[]
for i in range(N):
    a,b=input().split()
    mixlist.append((int(a),b))
print(mixlist)
"複数行にintとstrを複合して入力するやつ，今回はリスト一つで処理している"
#1 a
#2 b
とかに使う
'''

'''
#array=[input().split()for i in range(N)]
#print(type(array[0][0]))
#print(array)
"正方行列にstr型の値を入力"
'''

#brray=[list(map(int, input().split(" ")))for i in range(N)]
#print(type(brray[0][0]))
#print(brray)
'''
入力
1 2
4 5
7 8
出力結果
[[1, 2], [4, 5], [7, 8]]
'''
"列数に関して自由度の高いint型の値を入力するタイプの行列"
#以下に別解を記載
#N, M = [int(i) for i in input().split()]
'''
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()
#a=[int(i) for i in s]
#print(a[0])
#print([a])
#単数値．桁ごとに分割したい．入力と出力は以下の通り
#イメージとして1桁ごとにリストに値を入れているかんじ

'''
入力
1234
出力
1
[[1, 2, 3, 4]]
'''




'''
word_list= input().split(" ")
print(word_list[0])
"連続文字列の入力"
"qw er ty とかの入力に使う"
"入力すると空白で区切ったところでlistの番号が与えられる"
'''



'''
A, B, C=stdin.readline().rstrip().split()#何個でもいけることが多い
print(A)
"リストではなく独立したstr型を入れるなら以下のやり方でOK"
'''


#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)
#複数行の数値を入力して正方行列を作成

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = 0
diff = 0
for b, a in zip(B[::-1], A[::-1]):
    diff += b
    beat = min(diff, a)
    ans += beat
    diff -= beat
ans += min(diff, A[0], B[0]) # 1番目は一人で闘うのでmin(diff, A[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
diff = 0
for b, a in zip(B[::-1], A[::-1]):
    diff += b
    beat = min(diff, a)
    ans += beat
    diff -= beat
ans += min(diff, B[0]) # 1番目は一人で闘うのでmin(diff, A[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]+a[i+1] <= b[i]:
        ans += a[i]+a[i+1]
        continue
    if a[i] > a[i+1]:
        if a[i] >= b[i]:
            ans += b[i]
        else:
            ans += a[i]
        continue
    if a[i] < a[i+1]:
        if a[i+1] >= b[i]:
            ans += b[i]
        else:
            ans += 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
for i in range(n):
    if A[i] >= B[i]:
        ans += B[i]
        A[i] -= B[i]
    else:
        ans += A[i]
        B[i] -= A[i]
        ans += min(A[i+1], 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()))
#print(A,B)
A1 = []
for i in range(N):
    A1.append(A[i] + A[i+1])
#print(A1)

cnt = 0
for i in range(N):
    if A1[i] > B[i]:
        cnt += B[i]
    else:
        cnt +=A1[i]
print(cnt)

Submission status: Wrong Answer

Solution code:
def solve():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    c = 0
    for i in range(N):
        c += min(A[i], B[i])
        c += min(A[i+1], B[i] - min(A[i], B[i]))
    return c

print(solve())

Submission status: Wrong Answer

Solution code:
def solve():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    c = sum(A)
    B.append(0)
    B.append(0)
    for i in range(N+1):
        re = B[i] - A[i]
        if re >= 0:
            A[i] = 0
            B[i+1] += re
        else:
            A[i] -= B[i]

    return c - sum(A)

print(solve())

Submission status: Wrong Answer

Solution code:
def solve():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    c = sum(A)
    B.append(0)
    B.append(0)
    for i in range(N+1):
        re = B[i] - A[i]
        if re >= 0:
            A[i] = 0
            B[i+1] += re
        else:
            A[i] -= B[i]
            B[i+1] += -re

    return c - sum(A)

print(solve())

Submission status: Wrong Answer

Solution code:
N = int(input())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))
ans = 0
for i in range(N):
    ans += B_list[i] if A_list[i]-B_list[i]>=0 else A_list[i]
    tmp = B_list[i]
    B_list[i]-= A_list[i]
    A_list[i]-= tmp
    if B_list[i]>0:
        ans += B_list[i] if A_list[i+1]-B_list[i]>=0 else A_list[i+1]
        A_list[i+1]-= B_list[i] if A_list[i+1]-B_list[i]>=0 else 0
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
print(a)
print(b)
for i in range(n):
    if b[i] >= a[i] + a[i+1]:
        count += a[i] + a[i+1]
        a[i+1] = 0
    elif b[i] > a[i] and b[i] < a[i] + a[i+1]:
        count += b[i]
        a[i+1] -= b[i] - a[i]
    elif a[i] >= b[i]:
        count += b[i]
print(count)

Submission status: Wrong Answer

Solution code:
import sys
import os


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = int(sys.stdin.readline().rstrip())
    city = list(map(int, sys.stdin.readline().split()))
    brave = list(map(int, sys.stdin.readline().split()))

    ret = 0
    tmp = 0
    for n in range(N):
        ret += min(city[n], brave[n])
        ret += min(city[n + 1], brave[n] - min(city[n], brave[n]))

    print(ret)


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(N):
    ans += min(B[i],A[i]+A[i+1])
    if B[i]>A[i]:
        A[i+1] = max(0,B[i]-A[i])
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()))
tmp = 0
ans = 0
for i in range(n):
    if tmp > a_list[i]:
        ans += a_list[i]
        tmp = b_list[i]
        break
    else:
        a_list[i] -= tmp
        ans += tmp
        tmp = 0
    if a_list[i] > b_list[i]:
        ans += b_list[i]
        tmp = 0
    else:
        ans += a_list[i]
        tmp = b_list[i] - a_list[i]
if tmp > 0:
    if tmp > a_list[-1]:
        ans += a_list[-1]
    else:
        ans += tmp
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
# 配列入力の受け取り
arrA = list(map(int,input().split()))
arrB = list(map(int,input().split()))

mons = arrA[n]
res = 0
for i in range(n-1,-1,-1):
    mons += arrA[i]
    if mons>=arrB[i]:
        res += arrB[i]
        mons -= arrB[i]
    else:
        res += mons
        mons -= 0

print(res)

Submission status: Wrong Answer

Solution code:
n = int(input())
# 配列入力の受け取り
arrA = list(map(int,input().split()))
arrB = list(map(int,input().split()))

mons = arrA[n]
res = 0
for i in range(n-1,-1,-1):
    mons += arrA[i]
    if mons>=arrB[i]:
        res += arrB[i]
        mons -= arrB[i]
    else:
        res += mons
        mons -= mons

print(res)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]", B: "List[int]"):
    sum=0
    temp=0
    for i in range(N):
        if B[i]<=(A[i]-temp):
            sum+=B[i]+temp
            temp=0
        else:
            temp=B[i]-(A[i]-temp)
            sum+=A[i]
    
    if(A[N]>=temp):sum+=temp
    else: sum+=A[N]
    print(sum)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N + 1)]  # type: "List[int]"
    B = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A, B)

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(n):
    ans += min(a[i], b[i])
    # print(i, ans)
    if a[i] < b[i]:
        if a[i+1] <= b[i] - a[i]:
            ans += a[i+1]
            a[i+1] = 0
        else:
        # a[i+1] -= min(a[i+1], b[i] - a[i])
            ans += b[i] - a[i]
        # print(i, ans)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
list_A = list(map(int, input().split()))
list_B = list(map(int, input().split()))

ans = 0
re = 0

for i in range(n):
    if list_A[i] - list_B[i] - re >= 0:
        ans += list_B[i] + re
        re = 0
    else:
        ans += list_A[i]
        if list_A[i]-list_B[i] >= 0:
            re += list_B[i] -list_A[i]
        else:
            if list_A[i] >= re:
                re = list_B[i] - list_A[i]
            else:
                re = list_B[i]


if list_A[n]-re >= 0:
    ans += re
else:
    ans += list_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()))
c = 0
for i in range(n):
    c += min(a[i] + a[i + 1], b[i])
    a[i + 1] += max(min(0, a[i] - b[i]), 0)
print(c)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
B = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

ans = 0
temp = B[0]
for i in range(N) :
    if A[i] <= temp :
        ans += A[i]
        temp = B[i+1]
    if A[i] > temp :
        ans += temp
        if A[i] - temp <= B[i+1] :
            ans += A[i] - temp
            temp = B[i+1] - (A[i] - temp)
        else :
            ans += B[i+1]
            temp = 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
if a[0]<b[0]:
  cnt+=a[0]
  a[0]=0
  a[1]-=b[0]-a[0]
else:
  cnt+=b[0]
  a[0]-=b[0]
for i in range(1,n-1):
  if a[i]<b[i]:
    cnt+=a[i]
    a[i]=0
    a[i+1]-=b[i]-a[i]
  else:
    cnt+=b[i]
    a[i]-=b[i]
cnt+=min(a[n],b[n-1])
print(cnt)

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]
        nxt = min(a[i+1], b[i]-a[i])
        ans += nxt
        a[i] -= nxt
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-1):
    c=min(a[i],b[i])
    a[i]-=c
    b[i]-=c
    d=min(b[i],a[i+1])
    a[i+1]-=d
    ans+=c+d
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
for i in range(N):
    count+=min(A[i],B[i])
    if A[i]<B[i]:
        if A[i+1]<B[i]-A[i]:
            count+=A[i+1]
        else:
            count+=B[i]-A[i]
            A[i+1]-=B[i]-A[i]
print(count)

Submission status: Wrong Answer

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

x = a[n]
y = 0
z = 0
for i in range(n-1, -1, -1):
  x += a[i]
  y += b[i]
  #print(x,y)
  if x > y:
    z += y
    x -= y
    y = 0
    
  if x <= y:
    z += x
    x = 0
    y = 0
    
print(z)

Submission status: Wrong Answer

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

x = a[n]
y = 0
z = 0
for i in range(n-1, -1, -1):
  x += a[i]
  y += b[i]
  #print(x,y)
  if x >= y:
    z += y
    x -= y
    y = 0
    
  if x < y:
    z += x
    x -= x
    y = 0
    
print(z)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
import itertools

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, *AB = map(int, read().split())
A = AB[:N + 1]
B = AB[N + 1:]

B.append(0)
ans = 0
rest = 0
for i, j in zip(A, B):
    x = min(rest, i)
    ans += rest
    i -= rest
    if i < j:
        ans += i
        rest = j - i
    else:
        ans += j
        rest = 0
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import itertools

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, *AB = map(int, read().split())
A = AB[:N + 1]
B = AB[N + 1:]

ans = 0
cnt = 0
for i, j in zip(A, B):
    ans += min(i, cnt)
    m = min(i, j)
    ans += m
    cnt = max(j - m, 0)
ans += min(A[-1], cnt)

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
AS = list(map(int, input().split()))
BS = list(map(int, input().split()))

monsters = 0

for i in range(N):
    fi1 = min(AS[i], BS[i])
    fi2 = min(AS[i + 1], BS[i] - fi1)
    if 0 < i < N - 1:
        AS[i + 1] -= fi2
    monsters += (fi1 + fi2)

print(monsters)

Submission status: Wrong Answer

Solution code:
N = int(input())
AS = list(map(int, input().split()))
BS = list(map(int, input().split()))

monsters = 0

for i in range(N):
    fi1 = min(AS[i], BS[i])
    fi2 = min(AS[i + 1], max(0, BS[i] - fi1))
    monsters += (fi1 + fi2)

print(monsters)

Submission status: Wrong Answer

Solution code:
N = int(input())
AS = list(map(int, input().split()))
BS = list(map(int, input().split()))

monsters = 0

for i in range(N):
    fi1 = min(AS[i], BS[i])
    fi2 = min(AS[i + 1], BS[i] - fi1)
    monsters += (fi1 + fi2)

print(monsters)

Submission status: Wrong Answer

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    A=LI()
    B=LI()
    ans = 0
    for i,b in enumerate(B):
        ans += max(0,min(A[i],b))
        b = max(0, b - A[i])
        if b:
            ans += max(0,min(A[i+1],b))
            A[i+1] -= b
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# ABC136 C-City Savers
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=0

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

Submission status: Wrong Answer

Solution code:
# ABC136 C-City Savers
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=0

for i in range(n):
    ans+=min(b[i],a[i+1])
    b[i]-=min(b[i],a[i+1])
    ans+=min(b[i],a[i])
    b[i]-=min(b[i],a[i+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()))
monster_count = 0

for i in range(N):
    a_1, a_2 = A_list[i], A_list[i+1]
    b = B_list[i]
    if b>=a_1:
        monster_count = monster_count + a_1
        b = b - a_1
    elif b<a_1:
        monster_count = monster_count + b
        continue

    if b>=a_2:
        monster_count = monster_count + a_2
    elif b<a_2:
        monster_count = monster_count + b
        a_2 = a_2 - b
        A_list[i+1] = a_2

print(monster_count)

Submission status: Wrong Answer

Solution code:
N = int(input())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))
monster_count = 0

for i in range(N):
    a_1, a_2 = A_list[i], A_list[i+1]
    b = B_list[i]
    if b>=a_1:
        monster_count = monster_count + a_1
        b = b - a_1
    elif b<a_1:
        monster_count = monster_count + b
        continue

    if b>=a_2:
        monster_count = monster_count + a_2
    elif b<a_2:
        monster_count = monster_count + b

print(monster_count)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
#貪欲法じゃダメ？
ans = 0
for i in range(n):
    if b[i] >= a[i]:
        ans += a[i]
        b[i] -= a[i]
    else:
        ans += b[i]
        b[i] = 0
    if b[i] >= a[i + 1]:
        ans += a[i + 1]
    else:
        ans += b[i]
print(ans)

"""
#DPを書きたいぞ
ans = [0] * n #i番目の勇者が倒すモンスターの数
if b[0] >= a[1] + a[0]:
    ans[0] = a[1] + a[0]
elif ans[0] <= b[0]:
    ans[0] = 
"""

Submission status: Wrong Answer

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

c = 0
for i in range(n, 0, -1):
    if a[i] <= b[i-1]:
        c += a[i]
        b[i-1] -= a[i]
        a[i] = 0
    else:
        c += b[i-1]
        b[i-1] = 0
        a[i] -= b[i-1]

    if b[i - 1] > 0:
        if a[i - 1] <= b[i - 1]:
            c += a[i - 1]
            b[i-1] -= a[i - 1]
            a[i - 1] = 0
        else:
            c += b[i - 1]
            b[i - 1] = 0
            a[i - 1] -= b[i - 1]

print(c)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
b.append(0)
ans = 0
for i in range(n + 1):
    beat = min(a[i], b[i])
    a[i] -= beat
    b[i] -= beat
    if i != n:
        b[i + 1] += b[i]
    ans += beat
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()]

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

print(cnt)

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, b in enumerate(B):
    l = min(A[i], b)
    b -= l
    r = min(A[i + 1], b)
    ans += l + r

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
for i in range(N):
  if A[i] >= B[i]  and A[i] >= 0:
    count += B[i]
    A[i] = A[i] - B[i]
  elif A[i] < B[i] and A[i] >= 0:
    if A[i+1]-B[i]+A[i] > 0:
      count += B[i]
    else:
      count += A[i] +A[i+1]
    A[i+1] = -1
    A[i] = -1
  elif A[i] < 0:
    if A[i+1] >= B[i]:
      count += B[i]
      A[i+1] = A[i+1]- B[i]
    else:
      count += A[i+1]
      A[i+1] -= 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):
  if A[i] >= B[i]  and A[i] >= 0:
    count += B[i]
    A[i] = A[i] - B[i]
  elif A[i] < B[i] and A[i] >= 0:
    if A[i+1]-B[i]+A[i] > 0:
      count += B[i]
    else:
      count += A[i] +A[i+1]
    A[i+1] -=  B[i] - A[i]
    A[i] = -1
  elif A[i] < 0:
    if A[i+1] >= B[i]:
      count += B[i]
      A[i+1] -= B[i]
    else:
      count += A[i+1]
    A[i+1] -= 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):
  if A[i] >= B[i]  and A[i] >= 0:
    count += B[i]
    A[i] = A[i] - B[i]
  elif A[i] < B[i] and A[i] >= 0:
    if A[i+1]-B[i]+A[i] > 0:
      count += B[i]
    else:
      count += A[i] +A[i+1]
    A[i+1] -=  B[i] - A[i]
    A[i] = 0
  elif A[i] < 0:
    if A[i+1] >= B[i]:
      count += B[i]
      A[i+1] -= B[i]
    else:
      count += A[i+1]
    A[i+1] -= 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
X = A[-1]
for i in range(N):
  if A[i] >= B[i]  and A[i] >= 0:
    count += B[i]
    A[i] = A[i] - B[i]
  elif A[i] < B[i] and A[i] >= 0:
    if A[i+1]-B[i]+A[i] > 0:
      count += A[i] + (A[i+1]-B[i]+A[i])
    else:
      count += A[i] +A[i+1]
    A[i+1] -=  B[i] - A[i]
    A[i] = 0
  elif A[i] < 0:
    if A[i+1] >= B[i]:
      count += B[i]
      A[i+1] -= B[i]
    else:
      count += A[i+1]
    A[i+1] -= 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):
  if A[i] >= B[i]:
    count += B[i]
  elif A[i] < B[i]:
    A[i+1] = A[i+1] - (B[i] - A[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):
  if B[i] >= A[i]:
    count += A[i]
    B[i] -= A[i]
    if B[i] >= A[i+1]:
      count += B[i]
      A[i+1] = 0
    else:
      count += B[i]
      A[i+1] -= B[i]
  else:
     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()))
s=0
for i in range(N):
  if A[i]>=B[i]:
    s+=B[i]
  if A[i]<B[i]:
    if (B[i]-A[i])>=A[i+1]:
      s=s+A[i]+A[i+1]
    if (B[i]-A[i])<A[i+1]:
      s=s+B[i]
      A[i+1]=A[i+1]-(B[i]-A[i])
print(s)

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]>B[i]:
    s+=B[i]
  if A[i]<=B[i]:
    if (B[i]-A[i])>A[i+1]:
      s=s+A[i]+A[i+1]
    if (B[i]-A[i])<=A[i+1]:
      s=s+B[i]
      A[i+1]=A[i+1]-(B[i]-A[i])
print(s)

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]>B[i]:
    s+=B[i]
  if A[i]<=B[i]:
    if (B[i]-A[i])>A[i+1]:
      s=s+A[i]+A[i+1]
    if (B[i]-A[i])<=A[i+1]:
      s=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()))


# Imperative solution
res = 0
rem = 0

for i in range(N):
    B[i] += rem
    mobs = min(A[i], B[i])
    rem = B[i] - mobs
    res += mobs

res += min(A[N], rem)
print(res)

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] >= 0:
        ans += b[i]
    else:
        if a[i+1] > b[i] - a[i]:
            ans += b[i]
            a[i+1] = a[i+1] - b[i] - a[i]
        else:
            ans += a[i+1] + a[i]
            a[i+1] = 0
print(ans)