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:
#import math
#import itertools
#import numpy as np
#from collections import deque
# sys.setrecursionlimit(10 ** 6)
#mod = 10 ** 9 + 7
#INF = 10 ** 9
#PI = 3.14159265358979323846

INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))

def do():
    n=INT()
    A=LIST()
    B=LIST()
    ans=0
    ta=A[0]
    for i in range(n):
        tb=B[i]
        ans+=min(ta,tb)
        ta,tb=max(0,ta-tb),max(0,tb-ta)
        ta+=A[i+1]
        ans+=min(ta,tb)
        ta=max(0,ta-tb)
        #print(ans,ta,tb)
    print(ans)

if __name__=='__main__':
    do()

Submission status: Wrong Answer

Solution code:
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline
import numpy as np

def main():
    n = int(input())
    mob=np.array(list(map(int,input().split())),dtype=int)
    bra=np.array(list(map(int,input().split())),dtype=int)
    ans=0

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


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()))
m = 0
ans = 0
for i in range(N):
    cnt = min(a[i],b[i]+m)
    ans += cnt
    m = b[i]+m-cnt
ans += min(a[N],m)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
la = list(map(int,input().split()))
lb = list(map(int,input().split()))
count = 0
for i in range(n):
  count += min(la[i],lb[i])
  if la[i]<lb[i]:
    if la[i+1] >= lb[i]-la[i]:
      count+=(lb[i]-la[i])
      la[i+1] == la[i+1]-(lb[i]-la[i])
    else:
      count+=la[i+1]
      la[i+1]==0
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
la = list(map(int,input().split()))
lb = list(map(int,input().split()))
count = 0
for i in range(n):
  if la[i]>=lb[i]:
    count+=lb[i]
  else:
    count+=la[i]
    if la[i+1] >= lb[i]-la[i]:
      count+=(lb[i]-la[i])
      la[i+1] == la[i+1]-(lb[i]-la[i])
    else:
      count+=la[i+1]
      la[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()))

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

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#ABC135 C

N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
S = 0
if A[0] > B[0]:
    S += B[0]
else:
    S += A[0]

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

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

print(S)

Submission status: Wrong Answer

Solution code:
#ABC135 C

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

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

if b[-1] <= a[-2]+a[-1]:
    cnt += b[-1]
else:
    cnt += a[-1]+a[-2]
print(cnt)

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

if b[-1] <= a[-2]+a[-1]:
    cnt += b[-1]
else:
    cnt += min(b[-1], a[-1]+a[-2])
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
residues = [0]*(N+1)
B.append(0)

cnt = 0
for i in range(0,N+1):
    #隣の町で余った勇者を現在の町へ増援
    #更に隣の町へは増援できないことに注意
    B[i] = B[i]+residues[i-1]
    if B[i] >= A[i]:
        cnt += A[i]
        residues[i] = B[i]-A[i] #次の町へ持ち越す勇者
    else:
        cnt += B[i]
        tmp = 0
        residues[i] = 0
        
print(cnt)

Submission status: Wrong Answer

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

cnt = 0
residue= 0 #前の勇者残り
tmp = 0 #前々の勇者残り
for i in range(0,N):
    #隣の町で余った勇者を現在の町へ増援
    #更に隣の町へは増援できないことに注意
    B[i] = B[i]+residue-tmp
    if B[i] >= A[i]:
        cnt += A[i]
        tmp = residue #持ち越せない勇者
        residue = B[i]-A[i] #次の町へ持ち越す勇者
    else:
        cnt += B[i]
        tmp = 0
        residue = 0

#最後の町
B.append(residue)
if B[N] >= A[N]:
    cnt += A[N]
    residue = B[N]-A[N]
else:
    cnt += B[N]

print(cnt)

Submission status: Wrong Answer

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

cnt = 0
residue= 0 #前の勇者残り
tmp = 0 #前々の勇者残り
for i in range(0,N):
    #隣の町で余った勇者を現在の町へ増援
    #更に隣の町へは増援できないことに注意
    B[i] = B[i]+residue-tmp
    tmp = residue
    if B[i] >= A[i]:
        cnt += A[i]
        residue = B[i]-A[i]
    else:
        cnt += B[i]
        residue = 0
        tmp = 0

#最後の町
B.append(residue)
if B[N] >= A[N]:
    cnt += A[N]
else:
    cnt += B[N]

print(cnt)

Submission status: Wrong Answer

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

cnt = 0
residue= 0 #前の勇者残り
tmp = 0 #前々の勇者残り
for i in range(0,N):
    #隣の町で余った勇者を現在の町へ増援
    #更に隣の町へは増援できないことに注意
    B[i] = B[i]+residue-tmp
    tmp = residue
    if B[i] >= A[i]:
        cnt += A[i]
        residue = B[i]-A[i]
    else:
        cnt += B[i]
        residue = 0

#最後の町
B.append(residue)
if B[N] >= A[N]:
    cnt += A[N]
else:
    cnt += B[N]

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) #変数用

cnt = 0
residue= 0 #前の勇者残り
for i in range(0,N+1):
    #前の町で余った勇者を現在の町へ増援
    B[i] = B[i]+residue 
    if B[i] >= A[i]:
        cnt += A[i]
        residue = B[i]-A[i]
    else:
        cnt += B[i]
        residue = 0

print(cnt)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())

    A = [int(i) for i in input().split()]
    B = [int(i) for i in input().split()]

    ans = 0
    for i in range(len(B)-1, -1, -1):
        m = min(A[i+1], B[i])
        ans += m
        A[i+1] -= m
        B[i] -= m

        m = min(A[i], B[i])
        ans += m
        A[i + 1] -= m
        B[i] -= m

    print(ans)

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

# 勇者iが倒せるモンスター数Ciは Ci <= min(A_i+A_i+1, B_i)
# 各々の勇者が倒せる数だけ倒す貪欲法で行く

C = [0]*N
for i in range(N):
    C[i] += min(A[i],B[i])
    C[i] += min(A[i+1],B[i]-min(A[i],B[i]))
    A[i+1] = A[i+1]-min(A[i]-B[i],0)

print(sum(C))

Submission status: Wrong Answer

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

# 勇者iが倒せるモンスター数Ciは Ci <= min(A_i+A_i+1, B_i)
# 各々の勇者が倒せる数だけ倒す貪欲法で行く

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

print(sum(C))

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

Submission status: Wrong Answer

Solution code:
from collections import deque,defaultdict,Counter
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from bisect import bisect_left,bisect_right
from math import sqrt,gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
from statistics import mean,median,mode
import sys
sys.setrecursionlimit(10 ** 6)

INF = float('inf')

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse=False):
    data.sort(key=lambda x:x[col],reverse=revese)
    return data

def mymax(data):
    M = -1*float('inf')
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float('inf')
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def mydictvaluesort(dictionary):
    return sorted( dictionary.items(), key=lambda x:x[1] )

def mydictkeysort(dictionary):
    return sorted( dictionary.items(), key=lambda x:x[0] )

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(' ')
        elif type(ls[0])==str:
            print(' '.join(ls))
        elif type(ls[0])==int:
            print(' '.join(map(str,ls)))
        else:
            print('Output Error')
    else:
        if len(ls)==0:
            print('')
        elif type(ls[0])==str:
            print(''.join(ls))
        elif type(ls[0])==int:
            print(''.join(map(str,ls)))
        else:
            print('Output Error')

def I():
    return int(input())

def MI():
    return map(int,input().split())

def RI():
    return list(map(int,input().split()))

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input()) for _ in range(n) ]

# ddict = defaultdict(lambda: 0)
# ddict = defaultdict(lambda: 1)
# ddict = defaultdict(lambda: int())
# ddict = defaultdict(lambda: list())
# ddict = defaultdict(lambda: float())

mod = 10**9 + 7

n = I()
a = RI()
b = RI()
d = list(reversed(a))

c1 = 0
for i in range(n):
    # print(f'i={i}')
    if a[i] >= b[i]:
        # print('A')
        c1 += b[i]
        a[i] -= b[i]
    elif (a[i]+a[i+1]) >= b[i]:
        # print('B')
        c1 += a[i]
        # a[i] = 0
        c1 += b[i] - a[i]
        a[i+1] -= (b[i] - a[i])
    elif (a[i]+a[i+1]) < b[i]:
        # print('C')
        c1 += a[i]
        # a[i] = 0
        c1 += a[i+1]
        a[i+1] = 0
    # print(c1,a)
# print(c1)

c2 = 0
for i in range(n):
    if d[i] >= b[i]:
        c2 += b[i]
    elif (d[i]+d[i+1]) >= b[i]:
        c2 += d[i]
        c2 += b[i] - d[i]
        d[i+1] -= b[i] - d[i]
    elif (d[i]+d[i+1]) < b[i]:
        c2 += d[i]
        c2 += d[i+1]
        d[i+1] = 0
    # print(c2,d)
# print(c2)

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
 
# 勇者1...1番目・2番目の街で、B_1体まで
# 勇者2...2番目・3番目の街で、B_2体まで
# 勇者N...N番目・(N+1)番目の街で、B_N体まで

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

ans -= sum(A)
print(ans)

Submission status: Wrong Answer

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

# 勇者1...1番目・2番目の街で、B_1体まで
# 勇者2...2番目・3番目の街で、B_2体まで
# 勇者N...N番目・(N+1)番目の街で、B_N体まで

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

print(sum(A))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
As = input().split(' ')
As = [int(As[i]) for i in range(N+1)]
Bs = input().split(' ')
Bs = [int(Bs[i]) for i in range(N)]
WIN = 0
for i in range(N):
  if Bs[i] > As[i]:
    WIN += As[i]
    Bs[i] -= As[i]
    As[i] = 0
    if Bs[i] > As[i+1]:
      WIN += As[i+1]
      Bs[i] -= As[i+1]
      As[i+1] = 0
    elif Bs[i] == As[i+1]:
      WIN += As[i+1]
      Bs[i] = 0
      As[i+1] = 0
    else:
      WIN += Bs[i]
      Bs[i] = 0
      As[i+1] -= Bs[i]
  elif Bs[i] == As[i]:
    WIN += As[i]
    Bs[i] = 0
    As[i] = 0
  else:
    WIN += Bs[i]
    Bs[i] = 0
    As[i] -= Bs[i]
print(WIN)

Submission status: Wrong Answer

Solution code:
n = int(input())
monster_list = list(map(int, input().split()))
kill_mon = list(map(int, input().split()))

# 配列数を合わせる
kill_mon.append(0)

# 持ち越しパワーの初期化
killed_monster = 0
carry_power = 0
for mons, kill in zip(monster_list, kill_mon):   
    # 全パワーを使い果たす
    if mons >= (kill + carry_power):
        killed_monster += (kill + carry_power)
        # 持ち越しパワーの初期化
        next_power = 0
    # 余力を残して勝利する
    else:
        killed_monster += mons
        # 前回余力は今回のモンスターにしか使えない。次回のバトルに持ち越せない
        # だから、mons - carry_powerとなる
        # ただ、前回余力が今回モンスターよりも多い場合も考慮するためmax関数を使いマイナス値になることを避ける
        # 前回余力だけで今回バトルに勝利したら、今回パワーをそのまま持ち越せる
        carry_power = kill - max(0, mons - carry_power)
print(killed_monster)

Submission status: Wrong Answer

Solution code:
n = int(input())
monster_list = list(map(int, input().split()))
kill_mon = list(map(int, input().split()))

# 配列数を合わせる
kill_mon.append(0)

# 持ち越しパワーの初期化
killed_monster = 0
carry_power = 0
for mons, kill in zip(monster_list, kill_mon):   
    # 全パワーを使い果たす
    if mons >= kill + carry_power:
        killed_monster += kill + carry_power
        # 持ち越しパワーの初期化
        next_power = 0
    # 余力を残して勝利する
    elif mons < kill + carry_power:
        killed_monster += mons
        # 前回余力は今回のモンスターにしか使えない。次回のバトルに持ち越せない
        # だから、mons - carry_powerとなる
        # ただ、前回余力が今回モンスターよりも多い場合も考慮するためmax関数を使いマイナス値になることを避ける
        # 前回余力だけで今回バトルに勝利したら、今回パワーをそのまま持ち越せる
        carry_power = kill - max(0, mons - carry_power)
print(killed_monster)

Submission status: Wrong Answer

Solution code:
n = int(input())
monster_list = list(map(int, input().split()))
kill_mon = list(map(int, input().split()))

# 配列数を合わせる
kill_mon.append(0)

# 持ち越しパワーの初期化
killed_monster = 0
next_power = 0
for mons, kill in zip(monster_list, kill_mon):
    kill += next_power
    # 全力で倒す
    if mons >= kill:
        killed_monster += kill
        # 持ち越しパワーの初期化
        next_power = 0
    elif mons < kill:
        killed_monster += mons
        next_power = kill - mons
print(killed_monster)

Submission status: Wrong Answer

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

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()]
B.append(0)

ans = 0
for i in range(N+1):
  taosukazu1 = min(A[i],B[i])
  B[i] -= taosukazu1
  A[i] -= taosukazu1
  ans += taosukazu1
  if B[i] > 0:
    taosukazu2 = min(A[i+1],B[i])
    B[i] -= taosukazu2
    A[i] -= taosukazu2
    ans += taosukazu2
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()]
B.append(0)

ans = 0
for i in range(N+1):
  taosukazu1 = min(A[i],B[i])
  B[i] -= taosukazu1
  ans += taosukazu1
  if B[i] > 0:
    taosukazu2 = min(A[i+1],B[i])
    B[i] -= taosukazu2
    ans += taosukazu2
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()]
B.append(0)

ans = 0
for i in range(N+1):
  taosukazu1 = min(A[i],B[i])
  B[i] -= taosukazu1
  ans += taosukazu1
  if taosukazu1 > 0:
    taosukazu2 = min(A[i+1],B[i])
    B[i] -= taosukazu2
    ans += taosukazu2
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

if a[-1] < 0:
    a[-1] = 0
print(sum_a - sum(a))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
B.append(0)
diff = 0
count = 0
for a,b in zip(A,B):
    if diff + a-b < 0:
        diff = diff +a-b
        count += a
    else:
        count +=  b - diff
print(count)

Submission status: Wrong Answer

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

if hero>0:
    monster += min(hero,A[N])
print(monster)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
monster = 0
hero = 0
for i in range(N):
    allhero = B[i] + hero
    if allhero<=A[i]:
        monster += B[i]
        hero = 0
    else:
        monster += A[i]
        minus = 0
        if hero>A[i]:
            minus = hero-A[i]
        hero = allhero-minus-A[i]
    #print(monster,allhero,hero)

if hero>0:
    monster += min(hero,A[N])
print(monster)

Submission status: Wrong Answer

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

if hero>0:
    monster += min(hero,A[N])
print(monster)

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

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

    if B[N-1-i] > 0:
        if A[N-i-1] > B[N-1-i]:
            A[N-i-1] -= B[N-1-i]
        else:
            A[N-i-1] = 0

print(ans-sum(A))

Submission status: Wrong Answer

Solution code:
import sys
import itertools
tokens = itertools.chain.from_iterable(map(str.split, sys.stdin))

n = int(next(tokens))
a = [int(next(tokens)) for _ in range(n + 1)]
b = [int(next(tokens)) for _ in range(n)]

# 0, n-1だけが担当できる区画がある
acc = 0

m = min(b[0], a[0])
b[0] -= m
acc += m

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

for i in range(n):
    m = min(b[i], a[i])
    b[i] -= m
    acc += m

print(acc)

Submission status: Wrong Answer

Solution code:
import sys
import itertools
tokens = itertools.chain.from_iterable(map(str.split, sys.stdin))

n = int(next(tokens))
a = [int(next(tokens)) for _ in range(n + 1)]
b = [int(next(tokens)) for _ in range(n)]

acc = 0
for i in range(n):
    m = min(b[i], a[i + 1])
    b[i] -= m
    acc += m
for i in range(n):
    m = min(b[i], a[i])
    b[i] -= m
    acc += m

print(acc)

Submission status: Wrong Answer

Solution code:
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
# from collections import Counter,defaultdict,deque
# from itertools import permutations, combinations
# from heapq import heappop, heappush
# # input = sys.stdin.readline
# sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
al = inpl()
bl = inpl()
ans = 0
rem = 0
for i in range(0, n):
    if(al[i] <= bl[i] + rem):
        tmp = al[i] - rem
        rem = bl[i] - tmp
        ans += al[i]
    else:
        ans += bl[i] + rem
        rem = 0
if(al[n] >= rem):
    ans += rem
else:
    ans += al[n]
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 n in range(N):
    if A[n] <= B[n]:
        cnt += A[n]
        B[n] -= A[n]
        if A[n+1] < B[n]:
            cnt += A[n+1]
            B[n] -= A[n+1]
        else:
            cnt += B[n]
            A[n+1] -= B[n]
    else:
        cnt += B[n]
        
print(cnt)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

cnt = 0
for n in range(N):
    if A[n] < B[n]:
        cnt += A[n]
        B[n] -= A[n]
        if A[n+1] < B[n]:
            cnt += A[n+1]
            B[n] -= A[n+1]
        else:
            cnt += B[n]
            A[n+1] -= B[n]
    else:
        cnt += B[n]
        
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]
  elif B[i] > A[i]:
    ans += A[i]
    ans += min(A[i+1],B[i]-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, v in enumerate(b):
    for j in range(2):
        m =  min(a[i+j], v)
        a [i] -= m
        v -= m
        ans += m
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()))
res = 0
for i in range(N-1):
  if List_A[i] >= List_B[i]:
    res += List_B[i]
  else:
    res += List_A[i]
    if List_A[i+1] >= List_B[i]-List_A[i]:
      res += List_B[i]-List_A[i]
      List_A[i+1] = List_A[i+1] - List_B[i] +List_A[i]
    else:
      res += List_A[i+1]
      List_A[i+1] = 0
print(res)

Submission status: Wrong Answer

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

count = 0
last = 0#前のBの余力
for i in range(N):
    at = min(A[i] - last, B[i])
    if at < 0:
        at = 0
    if at == 0:
        count += A[i]
    else:
        count += at + last
    last = B[i] - at
    
if A[-1]-last > 0:
    count += A[-1]-last
else:
    count += A[-1]
print(count)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# 問題：https://atcoder.jp/contests/abc135/tasks/abc135_c

n = int(input())
a = list(map(int, input().strip().split()))
b = list(map(int, input().strip().split()))

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

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):
    #i人目の勇者の戦闘
    rem = B[i] #残りの倒せるモンスター
    
    if A[i] >= rem:
        ans += rem
        continue
    else:
        rem -= A[i]
        ans += A[i]

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

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

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