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 = list( map( int, input().split() ) )
B_list = list( map( int, input().split() ) )
c = max(A_list[0], B_list[0])
remain_B = max(B_list[0] - A_list[0], 0)
for i in range(1, N ):
    c += min(remain_B, A_list[i])
    remain_A = max( A_list[i] - remain_B, 0 )
    c += min(remain_A, B_list[i])
    remain_B = max(B_list[i] - remain_A, 0 )
c += max(A_list[N], remain_B)
print(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):
  rem=B[i]-A[i]
  if rem<=0:
    cnt+=B[i]
  else:
    cnt+=A[i]
    A[i+1]-=rem
  if A[i+1]<0:
    A[i+1]=0
cnt+=rem

print(cnt)

Submission status: Wrong Answer

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

for i in range(N):
    tmp = min(A[i], surplus)
    ans += tmp
    A[i] -= tmp

    if B[i] > A[i]:
        ans += A[i]
        surplus = B[i] - A[i]

    else:
        ans += B[i]
        surplus = 0

tmp = min(A[i], surplus)
ans += tmp
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
monsters=[int(i) for i in input().split()]
powers=[int(i) for i in input().split()]
monsters.append(0)
powers.extend([0,0])

breaks=[]
for i in range(n+1):
  if monsters[i]>=powers[i]:
    breaks.append(powers[i])
  else:
    powers[i+1]=powers[i+1]+powers[i]-monsters[i]
    breaks.append(monsters[i])

print(sum(breaks))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

count = 0
prev = 0

for i in range(n):
    monsters = a_list[i] + a_list[i+1] - prev
    if b_list[i] > monsters:
        count += monsters
        prev = a_list[i+1]
    elif b_list[i] > a_list[i] - prev:
        count += b_list[i]
        prev = a_list[i+1] - b_list[i] - a_list[i] + prev
    else:
        count += b_list[i]
        prev = 0

print(count)

Submission status: Wrong Answer

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

    ans = 0
    for i in range(N):
        attack = min(A[i],B[i])
        A[i] -= attack
        B[i] -= attack
        ans += attack
        print('i: {}, attack: {}'.format(i,attack))
        if B[i] == 0:
            continue
        else:
            attack = min(A[i+1],B[i])
            A[i+1] -= attack
            B[i] -= attack
            ans += attack
            print('i: {}, attack: {}'.format(i,attack))
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

    ans = 0
    for i in range(N):
        attack = min(A[i],B[i])
        A[i] -= attack
        B[i] -= attack
        ans += attack
        if B[i] == 0:
            continue
        else:
            attack = min(A[i+1],B[i])
            A[i] -= attack
            B[i] -= attack
            ans += attack
    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()))
res = 0
rest = [0] * (N+1)
for i in range(N):
    diff = (B[i] + rest[i]) - A[i]
    if diff >= 0:
        res += A[i]
        rest[i+1] = diff
    else:
        res += (B[i] + rest[i])
res += rest[N] if A[N] >= rest[N] else A[N]
print(res)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S = str(input())
ans = [0] * 13
ans[0] = 1
MOD = 10**9 + 7
for i in S:
    dp = [0] * 13
    for j in range(13):
        dp[(j * 10) % 13] = ans[j] % MOD
    dp += dp
    if i == '?':
        for j in range(13):
            ans[j] = sum(dp[j+4:j+14])
    else:
        for j in range(13):
            ans[j] = dp[j + 13 - int(i)]
print(ans[5] % MOD)

Submission status: Wrong Answer

Solution code:
ans=0
n=int(input())
lista=list(map(int,input().split()))
listb=list(map(int,input().split()))
for i in range(n):
    if lista[i]+lista[i+1]>=listb[i]:
        if lista[i]>=listb[i]:
            ans+=listb[i]
            
        elif lista[i]<listb[i]:
            ans+=lista[i]
            lista[i+1]-=listb[i]-lista[i]
            listb[i]-=lista[i]
            j=max(listb[i],lista[i+1])
            ans+=j
            lista[i+1]-=j

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

res = 0

for i in range(len(A)-1):
    if B[i] >= A[i]:
        res += A[i]
        B[i+1] += B[i] - A[i]
    
    else:
        res += B[i]
 
if B[-1] >= A[-1]:
    res += A[-1]

else:
    res += B[-1]
  
print(res)

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(n):
  sum += min(A[i],B[i])
  if A[i] < B[i]:
    sum += B[i] - A[i]
    if B[i] >= A[i]+A[i+1]:
      A[i+1] = 0
    else:
      A[i+1] -= B[i]-A[i]
print(sum)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a_array = [int(x) for x in input().split()]
b_array = [int(x) for x in input().split()]
tmp = 0
ans = 0
for i in range(n):
    ans += min(b_array[i]+tmp, a_array[i])
    tmp = max(0, b_array[i]+tmp -a_array[i])
print(ans+min(tmp, a_array[-1]))

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):
    b  = B[i]
    a  = A[i]
    a2 = A[i+1]

    if a <= b:
        ans += a
        A[i] = 0
        b -= a
    else:
        ans += b
        A[i] -= b
        b = 0

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

    if a <= b:
        ans += a
        b -= a
        A[i] = 0
    else:
        ans += b
        b = 0
        A[i] -= b

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

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

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()]
mon = 0

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

B[N-1] = int(B[N-1]) - int(A[N-1])
if(B[N-1] > 0):
  if(int(A[N]) - int(B[N-1]) > 0):
    mon = mon + int(B[N-1])
  else:
    mon = mon + int(B[N-1]) - int(A[N])
print(mon)

Submission status: Wrong Answer

Solution code:
n = int(input())
monst = list(map(int,input().split()))
hero = list(map(int,input().split()))
attack = 0

for i in range(n):
    if monst[i] >= hero[i]:
        attack += hero[i]
        hero[i] = 0
    else:
        attack += monst[i]
        hero[i] = hero[i] - monst[i]
        if monst[i+1] > hero[i]:
            attack += hero[i]
            monst[i+1] = monst[i+1] - hero[i]
        else:
            attack +=  monst[i+1]
print(attack)

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

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],b[i])
  c+=max(0,b[i]-a[i])
  a[i+1]=min(a[i+1],a[i+1]+a[i]-b[i])
print(c)

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],b[i])
  c+=max(0,b[i]-a[i])
  a[i+1]=min(a[i],a[i+1]+a[i]-b[i])
print(c)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
result = 0
rem = 0
for n in range(N):
    result+= min(B[n], abs(A[n]+A[n+1]-rem))
    if B[n]>A[n]:
        rem = B[n]-A[n]
print(result)

Submission status: Wrong Answer

Solution code:
n=int(raw_input())
g=raw_input().split()
a=[int(x) for x in g]
g=raw_input().split()
b=[int(x) for x in g]
#n=len()
acc=0
for i in range(n):
	inc=min(a[i],b[i])
	a[i]-=inc
	b[i]-=inc
	acc+=inc
	inc=min(a[i+1],b[i])
	a[i]-=inc
	b[i]-=inc
	acc+=inc
print(acc)

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

Submission status: Wrong Answer

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

count = 0

for i in range(N):

  if A[i] >= B[i]:
    count += B[i]
  else:
    B[i] = B[i] - A[i]
    if B[i] >= A[i+1]:
      count += A[i+1]
    else:
      count += B[i]
    
  
print(count)

Submission status: Wrong Answer

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

print(A)
print(B)
# print(P_true)
def_Bsum = sum(B)

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

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

            if (A[i] < B[i]):
                B[i] -= A[i]
                A[i] = 0
            else:
                A[i] -= B[i]
                B[i] = 0

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


ans = def_Bsum - sum(B)
# print(def_Bsum)
# print(sum(B))

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

if b[n-1] <= a[n-1]:
    ans += b[n-1]
else:
    ans += a[n-1]
    b[n-1] -= a[n-1]

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

remain=0
count=0
for i in range(n):
    last_remain=remain
    remain=b[i]-a[i]+remain
    if remain<0:
        remain=0
        count+=last_remain+b[i]
    else:
        count+=a[i]

if a[n]-remain<0:
    count+=a[n]
else:
    count+=remain
print(count)

Submission status: Wrong Answer

Solution code:

N = int(input())
A_list = list(map(int,input().split()))
B_list = list(map(int,input().split()))
sum_cnt = 0

for i in range(N):
    for j in range(N+1):
        if B_list[i] ==0 or A_list[j] ==0:
            break
        if B_list[i]>=A_list[j]:
            sum_cnt += A_list[j]
            B_list[i] = B_list[i] -A_list[j]
            A_list[j] =0
        if B_list[i]<A_list[j]:
            sum_cnt += B_list[i]
            A_list[j] = A_list[j] - B_list[i]
            B_list[i] =0

print(sum_cnt)

Submission status: Wrong Answer

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

for i in range(N):
    for j in range(N+1):
        if B_list[i]>=A_list[j]:
            sum_cnt += A_list[j]
            B_list[i] = B_list[i] -A_list[j]
            A_list[j] =0
        if B_list[i]<A_list[j]:
            sum_cnt += B_list[i]
            A_list[j] = A_list[j] - B_list[i]
            B_list[i] =0
        if B_list[i] ==0:
            break


print(sum_cnt)

Submission status: Wrong Answer

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

cnt = 0
dbl = 1
while 1:
    if len(A) == 0 or len(B) == 0:
        break
    a = A.pop(0)
    b = B.pop(0)

    if b > a:
        cnt += a
        b -= a
        B.insert(0, b)

    elif b < a:
        cnt += b
        a -= b
        dbl += 1
        if dbl < 2:
            A.insert(0, a)
        else:
            dbl = 0
    else:
        cnt += a
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
dbl = 0
while 1:
    if len(A) == 0 or len(B) == 0:
        break
    a = A.pop(-1)
    b = B.pop(-1)

    if b > a:
        cnt += a
        b -= a
        dbl += 1
        if dbl < 2:
            B.append(b)
        else:
            dbl = 0

    elif b < a:
        cnt += b
        a -= b
        A.append(a)
    else:
        cnt += a
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)

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

Submission status: Wrong Answer

Solution code:
from collections import deque

def main():
    n = int(input())
    a = list(int(x) for x in input().split())
    b = list(int(x) for x in input().split())
    
    que = deque(a)
    ans = 0
    
    for i in b:
        q1 = que.popleft()
        if i >= q1:
            ans += q1
            q2 = que.popleft()
            if i-q1 >= q2:
                ans += q2
                que.append(0)
            else: #i-q1 < q2
                ans += i-q1
                que.append(q2-(i-q1))
        else: #i < q1
            ans += i
            que.append(q1-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()))
max = sum(b)

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A_l = list(map(int, input().split()))
B_l = list(map(int, input().split()))

# 番号が若い勇者、番号が若い街から可能な限りモンスターを倒せばよい

killed_monsters = 0

for idx in range(N-1):
    killed_monsters += B_l[idx]
    if B_l[idx] - A_l[idx] > 0:
        A_l[idx+1] = max(0, A_l[idx+1] - (B_l[idx] - A_l[idx]))

killed_monsters += min(A_l[-2] + A_l[-1], B_l[-1])

print(killed_monsters)

Submission status: Wrong Answer

Solution code:
N = int(input())
A_l = list(map(int, input().split()))
B_l = list(map(int, input().split()))

# 番号が若い勇者、番号が若い街から可能な限りモンスターを倒せばよい

killed_monsters = 0

for idx in range(N-1):
    killed_monsters += B_l[idx]
    if B_l[idx] - A_l[idx] > 0:
        A_l[idx+1] -= max(0, B_l[idx] - A_l[idx])

killed_monsters += min(A_l[-2] + A_l[-1], B_l[-1])

print(killed_monsters)

Submission status: Wrong Answer

Solution code:
N = int(input())
A_l = list(map(int, input().split()))
B_l = list(map(int, input().split()))

# 番号が若い勇者、番号が若い街から可能な限りモンスターを倒せばよい

killed_monsters = 0

for idx in range(N-1):
    if B_l[idx] - A_l[idx] > 0:
        A_l[idx+1] -= B_l[idx] - A_l[idx]
        killed_monsters += B_l[idx]
    else:
        killed_monsters += B_l[idx]

killed_monsters += min(A_l[-2] + A_l[-1], B_l[-1])

print(killed_monsters)

Submission status: Wrong Answer

Solution code:
N = int(input())
A_l = list(map(int, input().split()))
B_l = list(map(int, input().split()))

# 番号が若い勇者、番号が若い街から可能な限りモンスターを倒せばよい

killed_monsters = 0

for idx in range(N-1):
    if B_l[idx] - A_l[idx] > 0:
        A_l[idx+1] -= B_l[idx] - A_l[idx]
        killed_monsters += A_l[idx]
    else:
        killed_monsters += B_l[idx]

killed_monsters += min(A_l[-2] + A_l[-1], B_l[-1])

print(killed_monsters)

Submission status: Wrong Answer

Solution code:
N = int(input())
A_l = list(map(int, input().split()))
B_l = list(map(int, input().split()))

# 番号が若い勇者、番号が若い街から可能な限りモンスターを倒せばよい
# i番目の勇者の戦力-i番目の街のモンスターの数 が正ならば、その分だけi+1番目の勇者の戦力が増減すると考える

killed_monsters = 0

for idx in range(N-1):
    if B_l[idx] - A_l[idx] > 0:
        B_l[idx+1] += B_l[idx] - A_l[idx]
        killed_monsters += A_l[idx]
    else:
        killed_monsters += B_l[idx]

killed_monsters += min(A_l[-2] + A_l[-1], B_l[-1])

print(killed_monsters)

Submission status: Wrong Answer

Solution code:
N = int(input())
A_l = list(map(int, input().split()))
B_l = list(map(int, input().split()))

# 番号が若い勇者、番号が若い街から可能な限りモンスターを倒せばよい
# i番目の勇者の戦力-i番目の街のモンスターの数 が正ならば、その分だけi+1番目の勇者の戦力が増減すると考える

rest_monsters = 0

for idx in range(N-1):
    if B_l[idx] - A_l[idx] > 0:
        B_l[idx+1] += B_l[idx] - A_l[idx]
    else:
        rest_monsters += abs(B_l[idx] - A_l[idx])

rest_monsters += max(0, A_l[-2] + A_l[-1] - B_l[-1])

print(sum(A_l) - rest_monsters)

Submission status: Wrong Answer

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

ans=0
z=0

for i in range(N):
    if A[i]>B[i]+z:
        ans+=B[i]+z
    else:
        ans+=A[i]
        z=B[i]-A[i]+min(z,A[i])

print(ans+min(z,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
z=0

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

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

p=0
W=0
for i in range(N):
    pp=p
    p=B[i]-A[i]+pp
    if p>=0:
        w=A[i]
    else:
        p=0
        w=A[i]-B[i]-pp
    W+=w
if A[N]>=p:
    W+=p
else:
    W+=A[N]


print(W)

Submission status: Wrong Answer

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

p=0
W=0
for i in range(N):
    pp=p
    p=B[i]-A[i]+pp
    if p>=0:
        w=A[i]
    else:
        p=0
        w=A[i]-B[i]-pp
    W+=w

print(W)

Submission status: Wrong Answer

Solution code:
N=int(input())
Enemy=[i for i in map(int,input().split())]
Hero=[i for i in map(int,input().split())]
ans=0
EX=0
for i in range(1,N+1) :
    if Enemy[i-1]-EX>=Hero[i-1]:
        ans += Hero[i-1]
        EX=0
    else:
        EX=Hero[i-1]-Enemy[i-1]-EX
        if sum(Enemy[i-1:i+1]) >= Hero[i-1]:
            ans += Hero[i-1]
        else:
            ans += sum(Enemy[i-1:i+1])
            EX=Enemy[i]
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
Enemy=[i for i in map(int,input().split())]
Hero=[i for i in map(int,input().split())]
ans=0
EX=0
for i in range(N) :
    if Enemy[i]-EX>=Hero[i]:
        ans += Hero[i]
        EX=0
    else:
        EX=Hero[i]-Enemy[i]
        if sum(Enemy[i:i+2]) >= Hero[i]:
            ans += Hero[i]
        else:
            ans += sum(Enemy[i:i+2])
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
num=0
for i in range(n):
  num+=min(a[i],b[i])
  b[i]=max(0,b[i]-a[i])
  num+=min(b[i]-a[i],a[i+1])
  a[i+1]=max(0,a[i+1]-b[i])
print(num)

Submission status: Wrong Answer

Solution code:
n = int(input())
L1 = list(map(int,input().split()))
L2 = list(map(int,input().split()))

cnt = 0
for i in range(n):
      if L1[i] > L2[i]:
            cnt += L2[i]
      else:
            cnt += L1[i]
            if L1[i + 1] > L2[i] - L1[i]:
                  cnt += L2[i] - L1[i]
            else:
                  cnt += L1[i + 1]
                  L1[i + 1] = 0
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
L1 = list(map(int,input().split()))
L2 = list(map(int,input().split()))

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

Submission status: Wrong Answer

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
B.append(0)

monster_count = 0
next_saver = 0

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
L1=list(map(int,input().split()))
L2=list(map(int,input().split()))

c=0
for i in range(n):
      if L2[i] < L1[i]:
            c += L2[i]
      else:
            c += L1[i]
            e = L2[i] - L1[i]
            if L1[i+1]>e:
                  c += e
                  L1[i+1] = L1[i+1]-e
            else:
                  c += L1[i+1]
      
print(c)

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

ans = 0


# =============================================================================
# for i in range(N):
#     if(A[i] > B[i]):
#         # 全て倒せない
#         ans += B[i]
#         A[i] -= B[i]
#     else:
#         # 全て倒せる
#         B[i] -= A[i]
#         ans += A[i]
#         A[i] = 0
#         # 次の場所へ
#         if(A[i+1] > B[i]):
#             #次の場所はすべて倒せない
#             ans += B[i]
#             A[i+1] -= B[i]
#         else:
#             #次の場所もすべて倒せる
#             ans += A[i+1]
#             A[i+1] = 0
# =============================================================================

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

print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
N=int(input())

A=list(map(int,input().split()))
B=list(map(int,input().split()))

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

print(A)
print(B)
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):
    hiku=min(A[i],B[i])
    count+=hiku
    B[i]-=hiku
    hiku=min(A[i+1],B[i])
    count+=hiku
    B[i]-=hiku

print(count)

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)
C[0] = B[0] - A[0]

B.append(0)

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

nokill = 0
for i in range(0, N + 1):
    if C[i] < 0:
        nokill += abs(C[i])

print(sum(A) - nokill)