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

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

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

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




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

# print(A)

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

sa = sum(A)

for i, b in enumerate(B):
    tmp = min(A[i], b)  
    A[i] -= tmp　　
    A[i + 1] -= min(A[i + 1], b - tmp)　　

print(sa - sum(A))　　

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

sa = sum(A)

for i, b in enumerate(B):
    tmp = min(A[i], b)  
    A[i] -= tmp  
    A[i + 1] -= min(A[i + 1], b - tmp)  

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

monster = 0
addPower = 0

for i in range(N):
    print(A[i],'+', A[i+1], ' vs ', B[i], end = ' => ')
    AA = A[i] + A[i+1]
    BA = B[i] - A[i]
    BAA= B[i] - AA
    if BAA >= 0:
        print(':', end='')
        monster += AA
        A[i+1] -= min(A[i+1], BA)
    elif BA > 0:
        print('%', end='')
        monster += B[i]
        A[i+1] -= min(A[i+1], BA)
    else:
        print('@', end='')
        monster += B[i]
    print(monster)

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

monster = 0
addPower = 0

for i in range(N):
    #print(A[i],'+', A[i+1], ' vs ', B[i], end = ' => ')
    AA = A[i] + A[i+1]
    BA = B[i] - A[i]
    BAA= B[i] - AA
    if BAA >= 0:
        #print(':', end='')
        monster += AA
        A[i+1] -= min(A[i+1], BA)
    elif BA > 0:
        #print('%', end='')
        monster += B[i]
        A[i+1] -= min(A[i+1], B[i])
    else:
        #print('@', end='')
        monster += B[i]

print(monster)

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

monster = 0
addPower = 0

for i in range(N):
    #print(A[i],'+', A[i+1], ' vs ', B[i], end = ' => ')
    AA = A[i] + A[i+1]
    BA = B[i] - A[i]
    BAA= B[i] - AA
    if BAA >= 0:
        #print(':', end='')
        monster += AA
        A[i+1] -= min(A[i+1], BA)
    elif BA > 0:
        #print('%', end='')
        monster += B[i]
        A[i+1] -= min(A[i+1], BA)
    else:
        #print('@', end='')
        monster += B[i]
print(monster)

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

attack = 0

for i in range(N):
  if i != (N-1):
    if a[i] > b[i]:
      attack += b[i]
      a[i] = a[i]-b[i]
      b[i] = 0
    else:
      attack += a[i]
      a[i] = 0
      b[i] = b[i]-a[i]
      if (b[i]-a[i]) > 0:
        attack += min(a[i+1], b[i])
        a[i+1] = max(a[i+1]-b[i], 0)
        b[i] = 0
  else:
    if a[N-1] > b[N-1]:
      attack += b[i]
      a[N-1] = a[N-1]-b[N-1]
      b[N-1] = 0
    else:
      attack += a[N-1]
      a[N-1] = 0
      b[N-1] = b[N-1]-a[N-1]
      if (b[N-1]-a[N-1]) > 0:
        attack += min(a[N], b[N-1])
        a[N] = max(a[N]-b[N-1], 0)
        b[N-1] = 0

print(attack)

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]) + min(A[i+1], max(B[i] - A[i], 0))
  A[i+1] = max(0, A[i+1] - max(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()) 
A = list(map(int,input().split())) 
B = list(map(int,input().split())) 

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

print(ans)

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

for i in range(N): 
    d = min(A[i], B[i]) 
    ans += d 
    A[i] -= d 
    B[i] -= d 
    d = min(A[i + 1], B[i]) 
    ans += d 
    A[i + 1] -= d 
    B[i] -= d 

print(ans)

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

import sys
input = sys.stdin.readline
    
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]
    if a[i + 1] <= b[i]:
      ans += a[i + 1]
      a[i + 1] = 0
    else:
      ans += b[i]
      a[i + 1] -= b[i]
  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):
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)

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 += min(A_l[idx], B_l[idx])
    if B_l[idx] - A_l[idx] > 0:
        killed_monsters += min(B_l[idx] - A_l[idx], A_l[idx+1])
        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)

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):
i = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = []
d = 0
e = 0
z = 0
y = 0

for f in range(i):
    d = b[f] - a[f]
    if d > 0:
        z = z + a[f]
        y = a[f+1]
        a[f+1] = a[f+1] - d
        if a[f+1] <= 0:
            a[f+1] = 0
            z = z + y
        else:
            z = z + y
    elif d < 0:
        z = z + b[f]
    else:
        z = z + a[f]
print(z)

i = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = []
d = 0
e = 0
z = 0
y = 0

for f in range(i):
    d = b[f] - a[f]
    if d > 0:
        z = z + a[f]
        y = a[f+1]
        a[f+1] = a[f+1] - d
        if a[f+1] <= 0:
            a[f+1] = 0
            z = z + y
        else:
            z = z + d
    elif d < 0:
        z = z + b[f]
    else:
        z = z + a[f]
print(z)

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):
# -*- coding: utf-8 -*-

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

count = 0

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

    if (A[i] > 0) and (B[i] > 0):
        tmp = min(A[i],B[i])
        count += tmp
        A[i] -= tmp
        B[i] -= tmp

print(count)


# -*- coding: utf-8 -*-

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

count = 0

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

    if (A[i] > 0) and (B[i] > 0):
        tmp = min(A[i],B[i])
        count += tmp
        A[i] -= tmp
        B[i] -= tmp

if (A[N] > 0) and (B[N-1] > 0):
    tmp = min(A[N],B[N-1])
    count += tmp
    A[N] -= tmp
    B[N-1] -= tmp 

print(count)


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):
# -*- coding: utf-8 -*-                                                                              

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

killed = 0

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

print(killed)


# -*- coding: utf-8 -*-                                                                              

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

killed = 0

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

print(killed)


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

print(ans)

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

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

b_rest = [max(b[0]-a[0],0)]
a_rest = [max(a[0]-b[0],0)]

for i in range(1, n-1):
  b_rest.append( min(b[i], max( ((b[i]+b_rest[i-1])-a[i]), 0 ) ) )
  a_rest.append( max( a[i]-(b[i]+b_rest[i-1]), 0 ) ) 

a_rest.append(max(0, (a[n-1]-b_rest[-1]) ) )
ans = sum(a) - sum(a_rest)
                                
print(ans)

n = int(input())
# the num of monster in the cith A[i]
a = list(map(int, input().split()))
# the num of monster the hero can defeat
b = list(map(int, input().split()))


b_rest = [max(b[0]-a[0],0)]
a_rest = [max(a[0]-b[0],0)]


for i in range(n-1):
  b_rest.append( min( b[i+1], max( ((b[i+1]+b_rest[i])-a[i+1]), 0 ) ) )
  a_rest.append( max( a[i+1]-(b[i+1]+b_rest[i]), 0 ) ) 

a_rest.append(max(0, (a[n]-b_rest[-1]) ) )
ans = sum(a) - sum(a_rest)
                                
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())
monsters = list(map(int, input().split()))
heros = list(map(int, input().split()))

def f(i, j):
  if i == j == 1:
    return min(monsters[i], heros[i])
  if i == j - 1:
    return min(monsters[i+1], heros[i] - f(i, i)
  if i == j:
	return min(monsters[i] - f(i-1, i), heros[i])

s = 0
for i in range(1, 1+n):
	s += f(i, i) + f(i, i+1)


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

sum_A = sum(A)

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

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

if A[-1] > 0:
  ans += max(0,B[-1]-A[-2])
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(A[i], B[i])
  A[i+1] -= max(0, B[i]-A[i])

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

if A[-1] > 0:
  ans += max(0,B[-1]-A[-2])
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] <= B[i] < A[i]+A[i+1]:
    ans += B[i]
    A[i+1] -= B[i] - A[i]
  elif A[i] + A[i+1] <= B[i]:
    ans += A[i] + A[i+1]
    A[i+1] = 0

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


c = []
count = 0

for i in range(n):

    if a[i] - b[i] >= 0:
        count += b[i]
    elif a[i] - b[i] < 0:
        count += a[i]
        if a[i+1] + (a[i] - b[i]) >0:
            a[i+1] = a[i+1] + (a[i] - b[i])
            count += (a[i]-b[i])
        elif a[i+1] + (a[i]-b[i]) <=0:
            count += a[i+1]
            a[i+1] = 0
            
print(count)

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


# In[]
c = []
count = 0

for i in range(n):

    if a[i] - b[i] >= 0:
        count += b[i]
    elif a[i] - b[i] < 0:
        count += a[i]
        if a[i+1] + (a[i] - b[i]) >0:
            a[i+1] = a[i+1] + (a[i] - b[i])
            count += (a[i]-b[i])
        elif a[i+1] + (a[i]-b[i]) <=0:
            count += a[i+1]
            a[i+1] = 0
            
print(count)

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


c = []
count = 0

for i in range(n):

    if a[i] - b[i] >= 0:
        count += b[i]
    elif a[i] - b[i] < 0:
        count += a[i]
        if a[i+1] + (a[i] - b[i]) >0:
            a[i+1] = a[i+1] + (a[i] - b[i])
            count -= (a[i]-b[i])
        elif a[i+1] + (a[i]-b[i]) <=0:
            count += a[i+1]
            a[i+1] = 0
            
print(count)

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):
#! /usr/bin/env python3
# -*- coding:utf-8 -*-

def city_saver(a, b):
    monster = 0
    for i in range(len(b)):
        monster += min(a[i], b[i])
        if(a[i]<b[i]):
            monster += min(b[i]-a[i], a[i+1])
            a[i+1] -= min(b[i]-a[i], a[i+1])
    return monster

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

if __name__ == "__main__":
    try:
    main()


#! /usr/bin/env python3
# -*- coding:utf-8 -*-

def city_saver(a, b):
    monster = 0
    for i in range(len(b)):
        monster += min(a[i], b[i])
        if(a[i]<b[i]):
            monster += min(b[i]-a[i], a[i+1])
            a[i+1] -= min(b[i]-a[i], a[i+1])
    return monster

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

if __name__ == "__main__":
    try:
    main()


#! /usr/bin/env python3
# -*- coding:utf-8 -*-

def city_saver(a, b):
    monster = 0
    for i in range(len(b)):
        monster += min(a[i], b[i])
        if(a[i]<b[i]):
            monster += min(b[i]-a[i], a[i+1])
            a[i+1] -= min(b[i]-a[i], a[i+1])
    return monster

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

if __name__ == "__main__":
    try:
    main()


#! /usr/bin/env python3
# -*- coding:utf-8 -*-

def city_saver(a, b):
    monster = 0
    for i in range(len(b)):
        monster += min(a[i], b[i])
        if(a[i]<b[i]):
            monster += min(b[i]-a[i], a[i+1])
            a[i+1] -= min(b[i]-a[i], a[i+1])
    return monster

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

if __name__ == "__main__":
    main()


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

flag=0
for m,i in enumerate(la):
  ans+=min(i,l[m])+l[m+1]-max(0,l[m+1]-i+min(i,l[m]))
  l[m+1]=max(0,l[m+1]-i+min(i,l[m]))
print(ans)


n=int(input())
l=list(map(int,input().split()))
la=list(map(int,input().split()))

ans=0
for m,i in enumerate(la):
  ans+=min(i,l[m])+l[m+1]-max(0,l[m+1]-i+min(i,l[m]))
  l[m+1]=max(0,l[m+1]-i+min(i,l[m]))
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()))

count = 0

for num in range(N):
    if A[num] >= B[num]:
        num_dead_monster = B[num]
    else:
        num_dead_monster = A[num]
    #print("now index", num_dead_monster)
    count += num_dead_monster
    A[num] -= num_dead_monster
    B[num] -= num_dead_monster
    
    if B[num] >= 1:
        if A[num+1] >= B[num]:
            num_dead_monster = B[num]
        else:
            num_dead_monster = A[num+1]
        count += num_dead_monster
        A[num+1] -= num_dead_monster
        #print("next index", B[num])
    
    #print("A", A)
    
    #print()

print("count", count)

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

count = 0

for num in range(N):
    if A[num] >= B[num]:
        num_dead_monster = B[num]
    else:
        num_dead_monster = A[num]
    #print("now index", num_dead_monster)
    count += num_dead_monster
    A[num] -= num_dead_monster
    B[num] -= num_dead_monster
    
    if B[num] >= 1:
        if A[num+1] >= B[num]:
            num_dead_monster = B[num]
        else:
            num_dead_monster = A[num+1]
        count += num_dead_monster
        A[num+1] -= num_dead_monster
        #print("next index", B[num])
    
    #print("A", A)
    
    #print()

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=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
for i in range(n):
  a[i]=max(a[i]-b[i],0)
  b[i]=max(b[i]-a[i],0)
for i in range(n):
  a[i+1]=max(b[i]-a[i+1],0)
print(sum(a))

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

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

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

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(i) for i in input().split()]
b=[int(i) for i in input().split()]
d=[0]*(n+2)
for i in range(n):
    d[i+1]=min(a[i]+a[i+1],b[i]+d[i])
print(sum(d)) 

n=int(input())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
b.append(0)
d=[0]*(n+2)
for i in range(n):
    d[i+1]=min(a[i]+a[i+1],b[i]+d[i])
print(d)    

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

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()))
A=a.copy()
for i in range(N-1,-1,-1):
  if A[i+1]-B[i]<=0:
    A[i+1]=0
    if A[i]-A[i+1]+B[i]>=0:
      A[i]=A[i]+A[i+1]-B[i]
    else:
      A[i]=0
  else:
    A[i+1]=A[i+1]-B[i]
print(sum(a)-sum(A))

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

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

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

    if A[i+1] >= B[i]:
        total += B[i]
        A[i+1] = A[i+1] - B[i]
    elif A[i+1] < B[i]:
        total += A[i+1]
        A[i+1] = 0

print(total)

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):
    left = min(A[i], B[i])
    B[i] -= left
    ans += left
    right = min(A[i + 1], B[i])
    A[i + 1] -= right
    B[i] -= right
    ans += right
 

n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
 
ans = 0
for i in range(n):
    left = min(A[i], B[i])
    B[i] -= left
    ans += left
    right = min(A[i + 1], B[i])
    A[i + 1] -= right
    ans += right
 
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()))
b.append(0)
sum1=0
rest=0
for i in range(N+1):
  sum1+=min(a[i],b[i]+rest)
  a[i]-=min(a[i],b[i]+rest)
  b[i]=min(b[i],b[i]+rest-min(a[i],b[i]+rest))
  if b[i]<a[i]:
    continue
  elif b[i]>a[i]:
    rest=b[i]-a[i]

print(sum1)

N=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
b.append(0)
sum1=0
rest=0
for i in range(N+1):
  x=min(a[i],b[i]+rest)
  sum1+=x
  a[i]-=x
  b[i]=min(b[i],b[i]+rest-x)
  if a[i]==0:
    rest=b[i]
  if b[i]==0:
    rest=0

print(sum1)

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

B_list = list(map(int, input().split()))

count = 0
for i in range(N):
  if(A_list[i] >= B_list[i]):
    count = count + B_list[i]
  elif(A_list[i] - B_list[i] <= A_list[i+1]):
    count = count + A_list[i] - B_list[i]
    A_list[i+1] = A_list[i+1] - (A_list[i] - B_list[i])
  else:
    count = A_list[i+1]
    A_list[i+1] = 0
print(count)


N = int(input())

A_list = list(map(int, input().split()))

B_list = list(map(int, input().split()))

count = 0
for i in range(N):
  
  
  if(A_list[i] >= B_list[i]):
    count = count + A_list[i]
  
  
  elif((B_list[i] - A_list[i]) < A_list[i+1]):
    count = count + (B_list[i] - A_list[i])
    A_list[i+1] = A_list[i+1] - (B_list[i] - A_list[i])
  
  else:
    count = count + A_list[i+1]
    A_list[i+1] = 0
    
print(count)




N = int(input())

A_list = list(map(int, input().split()))

B_list = list(map(int, input().split()))

count = 0
for i in range(N):
  
  
  if(A_list[i] >= B_list[i]):
    count = count + B_list[i]
    #print("1 : ",B_list[i])
    
  
  
  elif((B_list[i] - A_list[i]) < A_list[i+1]):
    count = count + A_list[i] + (B_list[i] - A_list[i])
    A_list[i+1] = A_list[i+1] - (B_list[i] - A_list[i])
    #print("2 : ",(B_list[i] - A_list[i])+A_list[i])
    
  
  else:
    count = count + A_list[i+1]+A_list[i]
    #print("3 : ",A_list[i+1]+A_list[i])
    A_list[i+1] = 0
    
  
    
print(count)



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



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

print(sum(c))

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



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

print(c,sum(c))

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



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

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

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

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

Verdicts: Runtime Error

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

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

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

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

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

Verdicts: Runtime Error

Runtime Error

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):
from sys import stdin
n = int(stdin.readline().rstrip())
A = list(map(int,stdin.readline().rstrip().split()))
B = list(map(int,stdin.readline().rstrip().split()))
point = 0
fa = min(A[0],B[0])
fb = min(A[1],B[0]-f00)
point += fb
point += fa
for i in range(1,n):
    fc = min(A[i]-fb,B[i])
    point += fc
    fb = min(A[i+1],B[i]-fc)
    point += fb
print(point)

from sys import stdin
n = int(stdin.readline().rstrip())
A = list(map(int,stdin.readline().rstrip().split()))
B = list(map(int,stdin.readline().rstrip().split()))
point = 0
f00 = min(A[0],B[0])
f12 = min(A[1],B[0]-f00)
point += f12
point += f0
for i in range(1,n):
    f11 = min(A[i]-f12,B[i])
    point += f11
    f12 = min(A[i+1],B[i]-f11)
    point += f12
print(point)

from sys import stdin
n = int(stdin.readline().rstrip())
A = list(map(int,stdin.readline().rstrip().split()))
B = list(map(int,stdin.readline().rstrip().split()))
point = 0
f00 = min(A[0],B[0])
f12 = min(A[1],B[0]-f00)
point += f12
point += f0
for i in range(1,n):
    f11 = min(A[i]-f12,B[i])
    point += f11
    f12 = min(A[i+1],B[i]-f11)
    point += f12
print(point)

from sys import stdin
n = int(stdin.readline().rstrip())
A = list(map(int,stdin.readline().rstrip().split()))
B = list(map(int,stdin.readline().rstrip().split()))
point = 0
fa = min(A[0],B[0])
fb = min(A[1],B[0]-fa)
point += fb
point += fa
for i in range(1,n):
    fc = min(A[i]-fb,B[i])
    point += fc
    fb = min(A[i+1],B[i]-fc)
    point += fb
print(point)

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


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+1] -= attack
            B[i] -= attack
            ans += attack
    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()))

E = 0

for i in range(N-1,-1,-1):
	for j in range(i+1,i-1,-1):
		if B[i] - A[j] > 0:
			E += A[j]
			B[i] = B[i] - A[j]
			A[j] = 0
			print(E)
		if B[i] - A[j] <= 0:
			E += B[i]
			B[i] = 0
			break
			
print(E)

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

E = 0

for i in range(0,N):
	for j in range(i,i+2):

		if B[i] - A[j] > 0:
			E += A[j]
			B[i] = B[i] - A[j]
			A[j] = 0
		if B[i] - A[j] <= 0:
			E += B[i]
			A[j] = A[j] - B[i]
			B[i] = 0
			break
	
print(E)

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

dp = [0]*N

for i in range(N):
  dp[i] = min(A[i], B[i])
  A[i], B[i] -= dp[i]
  if rem==0:
    tmp = min(A[i+1], B[i])
    dp[i] += tmp
    A[i+1] -= tmp
print(sum(dp))


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

dp = [0]*N 

for i in range(N):
  dp[i] = min(A[i], B[i])
  A[i] -= dp[i]
  B[i] -= dp[i]
  rem = A[i]
  if rem==0:
    tmp = min(A[i+1], B[i])
    dp[i] += tmp
    A[i+1] -= tmp
print(sum(dp))

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()))
remain=A[0]
ans1=0
for i in range(n):
    if B[i]<=remain:
        ans1+=B[i]
        remain=A[i+1]
    if B[i]>remain:
        ans1+=remain
        yoryoku=B[i]-remain
        if yoryoku>A[i+1]:
            ans1+=A[i+1]
            remain=0
        else:
            ans1+=yoryoku
            remain=A[i+1]-yoryoku
rA=reversed(A)
rB=reversed(B)
remain=rA[0]
ans2=0
for i in range(n):
    if rB[i]<=remain:
        ans2+=rB[i]
        remain=rA[i+1]
    if rB[i]>remain:
        ans2+=remain
        yoryoku=rB[i]-remain
        if yoryoku>rA[i+1]:
            ans2+=rA[i+1]
            remain=0
        else:
            ans2+=yoryoku
            remain=rA[i+1]-yoryoku
print(max(ans1,ans2))

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

total = 0
for i in reversed(range(len(B))):
    if i == 0:
        break
    if A[i+1] > 0:
        down1 = min(A[i+1], B[i])
        A[i+1] -= down1
        B[i] -= down1
        total += down1
    if B[i] > 0:
        down2 = min(A[i], B[i])
        A[i] -= down2
        B[i] -= down2
        total += down2
    # print("A:", A)
    

print(total)

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

total = 0

#     # print(i)
#     if A[i+1] >= B[i]:

#         B[i] = 0
#         continue
#     else:

#         B[i] -= A[i+1]
#         if A[i] >= B[i]:

#             A[i] -= B[i]
#         else:

for i in range(len(B)):
    temp = min(A[i], B[i])
    A[i] -= temp
    B[i] -= temp
    total += temp
    temp = min(A[i+1], B[i])
    A[i+1] -= temp
    B[i] -= temp
    total += temp
print(total)

Verdicts: Wrong Answer

Accepted
Problem: Given is a string S. Each character in S is either a digit (`0`, ..., `9`) or `?`.  Among the integers obtained by replacing each occurrence of `?` with a digit, how many have a remainder of 5 when divided by 13? An integer may begin with 0.  Since the answer can be enormous, print the count modulo 10^9+7.

Submission attempts (in order):
import numpy as np
MOD = 10 ** 9 + 7

dp = np.zeros(13, dtype = np.int64)
dp[0] = 1

move = np.arange(0,52,4) % 13
for s in input():
  prev = dp#[move]
  dp = np.zeros(13, dtype=np.int64)
  if s == '?':
    add = range(10)
  else:
    add = [int(s)]
  for x in add:
    dp[x:13] += prev[:13-x]
    dp[0:x] += prev[13-x:13]
  dp %= MOD
  
print(dp[5])


import sys
input = sys.stdin.readline
import numpy as np

MOD = 10 ** 9 + 7
S = input().rstrip()

ten = np.zeros(13, dtype=np.int64)
ten[:10] += 1
add_all = [ten]
for _ in range(5):
  add_all.append(add_all[-1][np.arange(0,52,4)%13])

add_single = [[x * 10 ** i for x in range(10)] for i in range(6)]

add_all_count = [0] * 6
constant_term = 0
for i,s in enumerate(S[::-1]):
  if s == '?':
    add_all_count[i%6] += 1
  else:
    constant_term += add_single[i%6][int(s)]

def convolve(x,y):
  z = np.convolve(x,y) % MOD
  z[:12] += z[13:25]
  return z[:13] % MOD

def nth_convolve(arr,n):
  if n == 1:
    return arr
  x = nth_convolve(arr,n>>1)
  x = convolve(x,x)
  return convolve(arr,x) if n & 1 else x

dp = np.zeros(13, dtype=np.uint64)
dp[constant_term % 13] = 1
for arr,n in zip(add_all, add_all_count):
  if n > 0:
    dp = convolve(dp, nth_convolve(arr,n))

print(dp[5])


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

import numpy as np

MOD = 10**9 + 7

S = read().rstrip().decode('utf-8')

num = [0,0,0,0,0,0]
ques = [0,0,0,0,0,0]
for i,x in enumerate(S[::-1]):
    i %= 6
    if x == '?':
        ques[i] += 1
    else:
        num[i] += int(x)

ten = np.array([1]*10+[0,0,0],dtype=np.uint64)

def power(n):
    # (1+x+...+x^9)^n, x^13=1
    if n == 0:
        x = np.zeros(13,dtype=np.uint64)
        x[0] = 1
        return x
    x = power(n//2)
    x = np.convolve(x,x) % MOD
    x[0:12] += x[13:25]; x = x[:13]; x[x>=MOD] -= MOD
    if n&1:
        x = np.convolve(x,ten)
        x[0:12] += x[13:25]; x = x[:13]; x %= MOD
    return x

dp = [power(n) for n in ques]

pow10 = [1,10,9,12,3,4]

x = power(0)
for i,y in enumerate(dp):
    p = pow10[i]
    y[p*np.arange(13)%13] = y.copy()
    x = np.convolve(x,y) % MOD
    x[0:12] += x[13:25]; x = x[:13]; x[x>=MOD] -= MOD

n = sum(p*n for p,n in zip(pow10,num))%13

answer = x[(18-n)%13]
print(answer)

Verdicts: Wrong Answer

Wrong Answer

Accepted