TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: 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?

Submission attempts (in order):
N = int(input())

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

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

print (S - sum(A))

N = int(input())

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

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

print (S - sum(A))

Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
cnt = 0
ans = 0

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

print(ans)

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
cnt = 0
ans = 0

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

print(ans)

Verdicts: Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
def getInt(): return int(input())

def getIntList(): return [int(x) for x in input().split()]

N = getInt()
A = getIntList()
B = getIntList()
sum = 0
sum += min(A[0],B[0])
sum += min(A[1],B[0]-min(A[0],B[0]))
for i in range(N-1):
    sum += min(A[i+1]-min(A[1],B[0]-min(A[0],B[0])),B[i+1])
    sum += min(A[i+2],B[i+1]-min(A[i+1],B[i+1]))
print(sum)

def getInt(): return int(input())

def getIntList(): return [int(x) for x in input().split()]

N = getInt()
A = getIntList()
B = getIntList()
sum = 0
sum += min(A[0],B[0])
sum += min(A[1],B[0]-min(A[0],B[0]))
for i in range(N-1):
    sum += min(A[i+1]-min(A[i+1],B[i]-min(A[i],B[i])),B[i+1])
    sum += min(A[i+2],B[i+1]-min(A[i+1],B[i+1]))
print(sum)

def getInt(): return int(input())

def getIntList(): return [int(x) for x in input().split()]

N = getInt()
A = getIntList()
B = getIntList()
sum = 0
sum += min(A[0],B[0])
f = min(A[1],B[0]-min(A[0],B[0]))
sum += f
print(sum)
for i in range(N-1):
    sum += min(A[i+1]-f,B[i+1])
    f = min(A[i+2],B[i+1]-min(A[i+1]-f,B[i+1]))
    sum += f
print(sum)

def getInt(): return int(input())

def getIntList(): return [int(x) for x in input().split()]

N = getInt()
A = getIntList()
B = getIntList()
sum = 0
sum += min(A[0],B[0])
f = min(A[1],B[0]-min(A[0],B[0]))
sum += f
for i in range(N-1):
    sum += min(A[i+1]-f,B[i+1])
    f = min(A[i+2],B[i+1]-min(A[i+1]-f,B[i+1]))
    sum += f
print(sum)

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
N = int(input())
A = [int(_) for _ in input().split()]
B = [int(_) for _ in input().split()]

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

print(monster)

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

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

Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
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)

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(A[i+1]-(B[i]-A[i]),0)
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
N = int(input())
p = input()
list1 = list(map(int,p.split()))

list2 = []
for i in range(1,N + 1):
    list2.append(i)

if list1 == list2:
    print("YES")
    exit()
for i in range(0,N):
    if list1[i] != i+1:
        if i+1 == list1[list1[i]-1]:
            list1[list1[i]-1] = list1[i]
            list1[i] = i+1
            

        if list1 == list2:
            print("YES")
            exit()
        else:
            print("NO")
            exit()

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

damagecost = 0
killmonster = 0
for i in range(n):
    if lb[i] <= la[i]:
        killmonster += lb[i]
    else:
        killmonster += la[i]
        damagecost = lb[i] - la[i]
        if damagecost >= la[i + 1]:
            killmonster += la[i + 1]
            la[i + 1] = 0
        else:
            killmonster += damagecost
            la[i + 1] = la[i + 1] - damagecost
print(killmonster)


Verdicts: Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
s=0
y=0
for i in range(n+1):
    v=max(0,a[i]-y)
    if v<=b[i]:
        s+=a[i]
        y=b[i]-v
    elif v>b[i]:
        s+=b[i]+y
        y=0
print(s)

n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
s=0
y=0
for i in range(n):
    v=max(0,a[i]-y)
    if v<=b[i]:
        s+=a[i]
        y=b[i]-v
    elif v>b[i]:
        s+=b[i]+y
        y=0
print(s+min(a[-1],y))

Verdicts: Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    tmp = 0
    ans = 0
    for i in range(n):
        mon = max(0, a[i] - tmp)

        if b[i] <= mon:
            ans += b[i] + tmp
            tmp = 0
        else:
            ans += a[i]
            tmp = b[i] - mon
    print(tmp)
    if tmp <= a[i + 1]:
        ans += tmp
    else:
        ans += a[i + 1]
    print(ans)

if __name__ == "__main__":
    main()

import sys
input = sys.stdin.readline

def main():
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    tmp = 0
    ans = 0
    for i in range(n):
        mon = max(0, a[i] - tmp)

        if b[i] <= mon:
            ans += b[i] + tmp
            tmp = 0
        else:
            ans += a[i]
            tmp = b[i] - mon
            
    if tmp <= a[i + 1]:
        ans += tmp
    else:
        ans += a[i + 1]
    print(ans)

if __name__ == "__main__":
    main()

Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = 0
for i in range(0,n+1):
  if a[i] > b[i]:
    c = c + b[i]
  elif a[i] <= b[i]:
    c = c + a[i]
    b[i] = b[i] - a[i]
    if b[i] < a[i+1]:
      c = c + b[i]
      a[i+1] = a[i+1] - b[i]
    else:
      c = c + a[i+1]
      a[i+1] = 0
print(c)

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


Verdicts: Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
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)


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

Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

s1 = sum(a)
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
    elif i == n:
        if a[i] < b[i - 1]:
            a[i] = 0
        else:
            a[i] -= b[i - 1]
            b[i] = 0
    else:
        if a[i] < b[i - 1]:
            a[i] = 0
        else:
            a[i] -= b[i - 1]
        if a[i] < b[i]:
            b[i] -= a[i]
            a[i] = 0
        else:
            a[i] -= b[i]
            b[i] = 0
print(s1 - sum(a))


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

s1 = sum(a)
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
    elif i == n:
        if a[i] < b[i - 1]:
            a[i] = 0
        else:
            a[i] -= b[i - 1]
            b[i - 1] = 0
    else:
        if a[i] < b[i - 1]:
            a[i] = 0
        else:
            a[i] -= b[i - 1]
        if a[i] < b[i]:
            b[i] -= a[i]
            a[i] = 0
        else:
            a[i] -= b[i]
            b[i] = 0
print(s1 - sum(a))


Verdicts: Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = 0
for i in range(n):
    if a[i] < b[i]:
        if a[i]+a[i+1] <= b[i]:
            c += a[i]+a[i+1]
            a[i+1] = 0
        else:
            c += a[i]
            a[i+1] -= (b[i]-a[i])
    elif a[i] >= b[i]:
        c += b[i]
    
print(c)


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


Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
import sys
sys.setrecursionlimit(100000000)
def input():
    return sys.stdin.readline()[:-1]
from bisect import *
from collections import *
from heapq import *

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


import sys
sys.setrecursionlimit(100000000)
def input():
    return sys.stdin.readline()[:-1]
from bisect import *
from collections import *
from heapq import *

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


Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
import sys

input = sys.stdin.readline

def main():
    ans = 0
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    t = 0
    for i in range(n):
        for j in range(i, i+2):
            if a[j] >= b[i]:
                a[j] -= b[i]
                ans += b[i]
                break
            else:
                ans += a[j]
                a[j] = 0
                b[i] -=  a[j]
    print(ans)

if __name__ == '__main__':
    main()

import sys

input = sys.stdin.readline

def main():
    ans = 0
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    for i in range(n):
        for j in range(i, i+2):
            if a[j] >= b[i]:
                a[j] -= b[i]
                ans += b[i]
                break
            else:
                ans += a[j]
                b[i] -=  a[j]
                a[j] = 0
    print(ans)

if __name__ == '__main__':
    main()

Verdicts: Wrong Answer

Accepted
Problem: 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?

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

print(bSum)


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

print(bSum)


Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
n = int(input())
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))

result = 0
sum_a = sum(a)
for i in range(n):
    if a[i] <= b[i]:
        b[i] -= a[i]
        a[i] = 0
        if a[i+1] <= b[i]:
            a[i+1] = 0
        else:
            a[i+1] -= b[i]
    else:
        a[i] -= b[i]
    print('a',a)
    print('b',b)
print(sum_a-sum(a))

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

Verdicts: Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
N = int(input().split())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
L = 0
for i in range(N):
  l = min(A[i], B[i])
  r = min(A[i + 1], B[i])
  A[i + 1] -= r
  L += l + r
print(L)

N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
L = 0
for i in range(N):
  l = min(A[i], B[i])
  B[i] -= l
  r = min(A[i + 1], B[i])
  A[i + 1] -= r
  L += l + r
print(L)

Verdicts: Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0

for i in range(n):
    print(a,b)
    if b[i] >= sum(a[i:i+2]):
        ans += sum(a[i:i+2])
        a[i+1] = 0
    elif a[i] >= b[i]:
        ans += b[i]
    elif a[i] < b[i]:
        ans += b[i]
        a[i+1] -= b[i] - a[i]
print(ans)

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

Verdicts: Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
b=[int(i) for i in input().split()]
sum=np.sum(b)
for i in reversed(range(n)):
  k = a[i+1]
  l = a[i]
  m = b[i]
 
  a[i+1] = max(k-m, 0)
  b[i] = max(m-k, 0)
 
  a[i] = max(l-b[i], 0)
  b[i] = max(b[i]-l, 0)
postsum=np.sum(b)
print(sum-postsum)
 

import numpy as np
n=int(input())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
sum=np.sum(b)
for i in reversed(range(n)):
  k = a[i+1]
  l = a[i]
  m = b[i]
 
  a[i+1] = max(k-m, 0)
  b[i] = max(m-k, 0)
 
  a[i] = max(l-b[i], 0)
  b[i] = max(b[i]-l, 0)
postsum=np.sum(b)
print(sum-postsum)

Verdicts: Runtime Error

Accepted
Problem: 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?

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

import numpy as np
from collections import deque
N = int(input())
A_list = np.array(list(map(int, input().split())))
B_list = np.array(list(map(int, input().split())))
monsters = A_list.sum()
A_list = np.append(0, A_list)
B_list = np.append(0, B_list)
B_list = np.append(B_list,0)




beated_list = np.zeros(N+1)

for i in range(1,N+2):
    beated_list[i-1] = A_list[i]-B_list[i]-max(0, B_list[i-1]-A_list[i-1])
    A_list[i] = max(0, A_list[i]-(B_list[i-1]-A_list[i-1]))
    print(beated_list)
beated_list = np.where(beated_list < 0, 0, beated_list)
rest_monsters = beated_list.sum()
ans = int(monsters - rest_monsters)
print(ans)

import numpy as np
from collections import deque
N = int(input())
A_list = np.array(list(map(int, input().split())))
B_list = np.array(list(map(int, input().split())))
monsters = A_list.sum()
A_list = np.append(0, A_list)
B_list = np.append(0, B_list)
B_list = np.append(B_list,0)




beated_list = np.zeros(N+1)

for i in range(1,N+2):
    beated_list[i-1] = A_list[i]-B_list[i]-max(0, B_list[i-1]-A_list[i-1])
    A_list[i] -= max(0, B_list[i-1]-A_list[i-1])
beated_list = np.where(beated_list < 0, 0, beated_list)
rest_monsters = beated_list.sum()
ans = monsters - rest_monsters
print(ans)

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

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ans = 0
p = 0

for index, i in enumerate(A):
  if index > len(B) - 1:
    if p > A[index]:
      ans += A[index]
    else:
      print(p)
      
    break

  if A[index] - (B[index] + p) < 0:
    ans += A[index]
    p = abs(A[index] - B[index] - p)
    continue

  ans += B[index]
  p = 0

print(ans)

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

ans = 0
p = 0

for index, i in enumerate(A):
  if index > len(B) - 1:
    if p > A[index]:
      ans += A[index]
    else:
      ans += p
      
    break

  if A[index] - (B[index] + p) < 0:
    ans += A[index]
    p = abs(A[index] - B[index] - p)
    continue

  ans += B[index]
  p = 0

print(ans)

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

ans = 0
p = 0

for index, i in enumerate(A):
  if index > len(B) - 1:
    if p > A[index]:
      ans += A[index]
    else:
      ans += p
      
    break

  if A[index] - (B[index] + p) < 0:
    ans += A[index]
    if p > A[index]:
      p = B[index]
    else:
      p = abs(A[index] - B[index] - p)
      
    continue

  ans += B[index] + p
  p = 0

print(ans)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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?

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

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

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

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

Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
N = input()
A = list((map(int,input().split()))
B = list(map(int,input().split()))

ans = 0
         
for i in range(0,N):
    left = A[i] - B[i]
	ans += min(A[i],B[i])
         
    if left < 0:
		right = A[i+1] - abs(left)
    	ans += min( A[i+1],abs(left))
		A[i+1] = right

print(ans)


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

ans = 0
         
for i in range(0,N):
      left = A[i] - B[i]
      ans += min(A[i],B[i])
         
      if left < 0:
          right = A[i+1] - abs(left)
          if right < 0: right = 0
          ans += A[i+1] - right
          A[i+1] = right

print(ans)


Verdicts: Runtime Error

Accepted
Problem: 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?

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

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


Verdicts: Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
n = int(input())
enemy = list(map(int, input().split()))
beat = list(map(int, input().split()))

def hoge(index, index1):
	if(index == 0 and index1 == 0):
		return min([enemy[0], beat[0]])
	elif(index1 - index == 1):
		return min([enemy[index1], beat[index] - hoge(index, index)])
	else:
		return min([enemy[index] - hoge(index - 1, index), beat[index] ])
  
res = 0
for i in range(n):
	print(i)  
	res += hoge(i, i) + hoge(i, i+1)
print(res)


n = int(input())
enemy = list(map(int, input().split()))
beat = list(map(int, input().split()))

def hoge(index, index1):
  if(index == 0 and index1 == 0):
  	return min([enemy[0], beat[0]])
  elif(index1 - index == 1):
    return min([enemy[index1], beat[index] - hoge(index, index)])
  else:
    return min([enemy[index] - hoge(index - 1, index), beat[index] ])
  
res = 0
for i in range(n):
	print(i)  
	res += hoge(i, i) + hoge(i, i+1)
print(res)


n = int(input())
enemy = list(map(int, input().split()))
beat = list(map(int, input().split()))

def hoge(index, index1):
	if(index == 0 and index1 == 0):
		return min([enemy[0], beat[0]])
	elif(index >= 0 and index1 - index == 1):
		return min([enemy[index1], beat[index] - hoge(index, index)])
	elif(index >= 1 and index1 == index):
		return min([enemy[index] - hoge(index - 1, index), beat[index] ])
	else:
      print(index, index1)
res = 0
for i in range(n):
	res += hoge(i, i) + hoge(i, i+1)
print(res)


n = int(input())
enemy = list(map(int, input().split()))
beat = list(map(int, input().split()))
ans = 0 
for i in range(n):
  
  left = min([enemy[i], beat[i]])
  ans += left
  beat[i] -= left
  
  right = min([enemy[i+1], beat[i]])
  ans += right
  enemy[i + 1] -= right
  beat[i] -= right
  
print(ans)


Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
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)

N = int( input() )
A_list = list( map( int, input().split() ) )
B_list = list( map( int, input().split() ) )
c = min(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 += min(A_list[N], remain_B)
print(c)


Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
N = int(input())
A = list(map(int,input().split(" ")))
B = list(map(int,input().split(" ")))
a = sum(A)
ans = 0
for i in range(N):
    tmp = A[i]+A[i+1]-B[i]
    ans = ans + max(0,tmp-A[i+1])
    A[i+1] = min(A[i+1],tmp)
    print(A)

print(a - ans)

N = int(input())
A = list(map(int,input().split(" ")))
B = list(map(int,input().split(" ")))
a = sum(A)
ans = 0
for i in range(N):
    tmp = A[i]+A[i+1]-B[i]
    ans = ans + max(0,tmp-A[i+1])
    A[i+1] = min(A[i+1],tmp)
    print(A)

print(a - ans)

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





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





Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
import numpy as np

N = int(input()) + 1

A = input().split()

B = input().split()

enemy = np.zeros(N)
saver = np.zeros(N)

beated = 0
over = 0

for i in range(N - 1):
    enemy[i] = int(A[N - i - 2])
    saver[i] = int(B[N - i - 2])

enemy[N - 1] = int(A[N - 1])

for i in range(N):
    if(enemy[i] - over > saver[i]):
        beated = beated + saver[i] + over
        over = 0
    else:
        beated = beated + enemy[i]
        over = saver[i] + over - enemy[i]
         
print(beated)

import numpy as np

N = int(input()) + 1

A = input().split()

B = input().split()

enemy = np.zeros(N)
saver = np.zeros(N)

beated = 0
over = 0

for i in range(N - 1):
    enemy[i] = int(A[N - i - 1])
    saver[i] = int(B[N - i - 2])

enemy[N - 1] = int(A[0])

for i in range(N):
    if(enemy[i] - over > saver[i]):
        beated = beated + saver[i] + over
        over = 0
    else:
        beated = beated + enemy[i]
        if(over - enemy[i]):
            over = saver[i]
        else:
            over = saver[i] + over - enemy[i]

print(int(beated))

import numpy as np

N = int(input()) + 1

A = input().split()

B = input().split()

enemy = np.zeros(N)
saver = np.zeros(N)

beated = 0
over = 0

for i in range(N - 1):
    enemy[i] = int(A[N - i - 1])
    saver[i] = int(B[N - i - 2])

enemy[N - 1] = int(A[0])

for i in range(N):
    if(enemy[i] - over > saver[i]):
        beated = beated + saver[i] + over
        over = 0
    else:
        beated = beated + enemy[i]
        if(over > enemy[i]):
            over = saver[i]
        else:
            over = saver[i] + over - enemy[i]

print(int(beated))

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
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 b[i]+c[i] > a[i]:
    if c[i]>=a[i]:
      ans = ans + a[i]
      c[i+1] = b[i]
    else:
      ans = ans = a[i]
      c[i+1] = b[i]+c[i]-a[i]
  else:
    ans = ans + b[i] + c[i]
if c[n]>a[n]:
  ans = ans + a[n]
else:
  ans = ans + c[n]
print(ans)



n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
begin = sum(a)
c = 0
for i in range(n):
  a[i] = a[i]-c[i] if a[i]>c[i] else 0
  c = 0
  a[i] = a[i]-b[i] if a[i]>b[i] else 0
  c = b[i] - a[i] if b[i]>a[i] else 0
a[n] = a[n]-c if a[n]>c else 0
after = sum(a)
print(begin-after)


n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
begin = sum(a)
c = 0
for i in range(n):
  a[i] = a[i]-c if a[i]>c else 0
  c = 0
  c = b[i] - a[i] if b[i]>a[i] else 0
  a[i] = a[i]-b[i] if a[i]>b[i] else 0
a[n] = a[n]-c if a[n]>c else 0
after = sum(a)
print(begin-after)

Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
n = int(input())
A=[]
for x in input().split():
    A.append(int(x))

B=[]
for x in input().split():
    B.append(int(x))

B.append(int(0))    

TOT = sum ( A )

print ( A )

for i in range (n) :
    KILL = min ( A[i], B[i] )
    A [i] = A [i] - KILL
    A [i+1] = A[i+1] - min (A[i+1], B[i] - KILL)
    print ( A )    
    
print ( TOT - sum ( A ) )

n = int(input())
A=[]
for x in input().split():
    A.append(int(x))

B=[]
for x in input().split():
    B.append(int(x))

B.append(int(0))    

TOT = sum ( A )

for i in range (n) :
    KILL = min ( A[i], B[i] )
    A [i] = A [i] - KILL
    A [i+1] = A[i+1] - min (A[i+1], B[i] - KILL)
    
print ( TOT - sum ( A ) )

Verdicts: Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
x=0
for i in range(n):
    if a[i]<=b[i]:
        x+=a[i]
        if a[i+1]>=b[i]:
            a[i+1]-=b[i]-a[i]
            x+=b[i]-a[i]
        else:
            x+=a[i+1]
            a[i+1]=0
            
        a[i]=0
    else:
        x+=b[i]
        a[i]-=b[i]
print(x)

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

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

Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
N = int(input())


S = input()
S = S.split()
A = list(map(int, S))
A_copy = list(map(int, S))

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


remain = 0

for i in range(len(B)):
    remain = int(A[i]-B[i])
    if remain <= 0:
        if A[i+1]+remain >= 0:
            A[i+1] = int(A[i+1] + remain)
        else:
            A[i+1] = 0
        A[i] = 0
    elif remain > 0:
        A[i] = remain



if A[N] == 0:
    print(sum(A_copy)-sum(A))


N = int(input())


S = input()
S = S.split()
A = list(map(int, S))
A_copy = list(map(int, S))

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


remain = 0

for i in range(len(B)):
    remain = int(A[i]-B[i])
    if remain <= 0:
        if A[i+1]+remain >= 0:
            A[i+1] = int(A[i+1] + remain)
        else:
            A[i+1] = 0
        A[i] = 0
    elif remain > 0:
        A[i] = remain



print(sum(A_copy)-sum(A))


Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
n=int(input())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
b.append(0)
cnt=0
for i in range(n):
  if a[i]>=b[i]:
    cnt+=b[i]
  if a[i]<b[i]:
    cnt+=a[i]
    a[i+1]-=b[i]-a[i]
    cnt+=min(b[i]-a[i+1], a[i+1])
    a[i+1]=max(a[i+1], 0)
print(str(cnt))
  

n=int(input())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
b.append(0)
cnt=0
for i in range(n):
  if a[i]>=b[i]:
    cnt+=b[i]
  if a[i]<b[i]:
    cnt+=a[i]
    cnt+=min(b[i]-a[i], a[i+1])
    a[i+1]=max(a[i+1]-b[i]+a[i],0)
print(str(cnt))
  

Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

cnt = 0
for i in range(N):
    if B[i] <= A[i]:
        cnt += B[i]
        B[i] = 0
        A[i] = 0
    else:
        cnt += min(B[i],A[i]+A[i+1])
        A[i] = 0
        A[i+1] = max(0,A[i+1]-(B[i]-A[i]))
    # print(A)
    
print(cnt)


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

cnt = 0
for i in range(N):
    if B[i] <= A[i]:
        cnt += B[i]
        A[i] = A[i]-B[i]
        B[i] = 0
    else:
        cnt += min(B[i],A[i]+A[i+1])
        A[i+1] = max(0,A[i+1]-(B[i]-A[i]))
        A[i] = 0
        B[i] = B[i] - min(B[i],A[i]+A[i+1])
    # print(A)
    
print(cnt)


Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = 0
for i in range(len(B)):
  if A[i] - B[i] >= 0:
    A[i] = A[i] - B[i]
    ans += B[i]
  else:
    ans += A[i]
    A[i] = 0
    if A[i+1] - (B[i] - A[i]) >= 0:
      A[i+1] = A[i+1] - (B[i] - A[i])
      ans += (B[i] - A[i])
    else:
      ans += A[i+1]
      A[i+1] = 0
  #print(ans, A)
print(ans)

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

Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = 0

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

n = int(input())
a = [int, for i in input().split()]
b = [int, for i in input().split()]
c = 0

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

n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = 0
 
for i in range(n):
  if a[i] >= b[i]:
    c += b[i]
  else:
    c += a[i]
    c += min(a[i+1],b[i]-a[i])
    if a[i+1] >= b[i]-a[i]:
      a[i+1] = a[i+1] - (b[i] - a[i])
    else:
      a[i+1] = 0
     
print(c)

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
N = int(input())
ans = []
A = [int(x) for x in input().split()]
moto = sum(A)
B = [int(x) for x in input().split()]
for i in reversed(range(N)):
  if A[i+1] >= B[i]:
    A[i+1] = A[i+1] -B[i]
  else:
    if A[i] >= B[i] -A[i+1]:
      A[i+1] = 0
      A[i] = A[i] + A[i+1] -B[i]
    else:
      A[i+1] = 0
      A[i] = 0
print(moto-sum(A))

N = int(input())
ans = []
A = [int(x) for x in input().split()]
moto = sum(A)
B = [int(x) for x in input().split()]
for i in reversed(range(N)):
  if A[i+1] >= B[i]:
    A[i+1] = A[i+1] -B[i]
  else:
    if A[i] >= (B[i] -A[i+1]):
      A[i] = A[i] + A[i+1] -B[i]
      A[i+1] = 0
    else:
      A[i+1] = 0
      A[i] = 0
print(moto-sum(A))
              

Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
n = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
B.append(0)
ans = 0
num = 0
for i in range(n+1):
  if num != 0:
    if A[i] - num <= 0:
      num = B[i]
      ans += A[i]
    else:
      A[i] -= num
      num = 0
      if A[i] >= B[i]:
        num = 0
        ans += B[i]
      else:
        num = B[i]-A[i]
        ans += A[i]
  else:
    if A[i] >= B[i]:
      num = 0
      ans += B[i]
    else:
      num = B[i]-A[i]
      ans += A[i]
print(ans)

n = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
B.append(0)
ans = 0
num = 0
for i in range(n+1):
  if num != 0:
    if A[i] - num <= 0:
      num = B[i]
      ans += A[i]
    else:
      a = A[i]
      b = num
      A[i] -= num
      num = 0
      if A[i] >= B[i]:
        num = 0
        ans += (B[i]+b)
      else:
        num = B[i]-A[i]
        ans += a
  else:
    if A[i] >= B[i]:
      num = 0
      ans += B[i]
    else:
      num = B[i]-A[i]
      ans += A[i]
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=0
for i in range(n):
  if a[i]>b[i]:
    c+=b[i]
  elif a[i]<=b[i]:
    c+=a[i]
    a[i+1]=b[i]-a[i]
    if a[i+1]<=0:
      a[i+1]=0
print(c)

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


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



Verdicts: Wrong Answer

Wrong Answer

Accepted