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())
monsters = [int(x) for x in input().rstrip("\n").split(" ")]
damages = [int(x) for x in input().rstrip("\n").split(" ")]
total_monsters = sum(monsters)
result = 0
remain = monsters[n]
for i in range(n-1,-1,-1):
  damage = damages[i]
  if damage <= remain:
    result += remain - damage
    remain = monsters[i]
  else:
    damage -= remain
    if monsters[i] >= damage:
      remain = monsters[i] - damage
    else:
      remain = 0
print(total_monsters - result)
  


n = int(input())
monsters = [int(x) for x in input().rstrip("\n").split(" ")]
damages = [int(x) for x in input().rstrip("\n").split(" ")]
total_monsters = sum(monsters)
result = 0
remain = monsters[n]
for i in range(n-1,-1,-1):
  
  damage = damages[i]
  monster = monsters[i]
  
  if damage <= remain:
    result += damage
    remain = monster
  else:
    damage -= remain
    result += remain
    if monster >= damage:
      remain = monster - damage
      result += damage
    else:
      result += monster
      remain = 0
print(result)
  


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

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
cnt = 0
dp_1 = [0]*(n)
dp_1[0] = min(a[0], b[0])
dp_2 = [0]*(n)
dp_2[0] = min(a[1], b[0]-min(a[0], b[0]))
for i in range(n-1):
    dp_1[i+1] = min(b[i+1], a[i+1] - dp_2[i])
    dp_2[i+1] = min(a[i+2], b[i+1] - dp_1[i+1])
print(sum(dp_1+dp_2))

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())) + [0]

ans = min(A[0], B[0])
rest = B[0] - ans
  
for i in range(N):
  
  curr = min(A[i+1], rest + B[i+1])
  rest = min(0, B[i+1] - curr)
  ans += curr
print(ans)

N = int(input())
A = list(map(int, input().split())) 
B = list(map(int, input().split())) + [0]

ans = min(A[0], B[0])
rest = B[0] - ans
  
for i in range(N):
  
  curr = min(A[i+1], rest + B[i+1])
  rest = min(0, rest + B[i+1] - curr)
  ans += curr
print(ans)

N = int(input())
A = list(map(int, input().split())) 
B = list(map(int, input().split())) + [0]

curr = min(A[0], B[0])
ans = min(A[0], B[0])

B[0] -= ans
  
for i in range(N):
  
  curr = min(A[i+1], B[i])
  ans += curr
  A[i+1] -= curr
  
  curr = min(A[i+1], B[i+1])
  ans += curr
  B[i+1] -= curr
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_lst = list(map(int,input().split()))
b_lst = list(map(int,input().split()))
monster = 0

for i in range(n):
    a1 = a_lst[i]
    a2 = a_lst[i+1]
    b1 = b_lst[i]
    tmp = b1-a1

    monster += min(a1,b1)
    if tmp>0:
        if a2-tmp<=0:
            monster += a2
            a_lst[i+1] = 0
        else:
            monster += tmp
            a_lst[i+1] -= tmp

print(monster)
print(a_lst)

n = int(input())
a_lst = list(map(int,input().split()))
b_lst = list(map(int,input().split()))
monster = 0

for i in range(n):
    a1 = a_lst[i]
    a2 = a_lst[i+1]
    b1 = b_lst[i]
    tmp = b1-a1

    monster += min(a1,b1)
    if tmp>0:
        if a2-tmp<=0:
            monster += a2
            a_lst[i+1] = 0
        else:
            monster += tmp
            a_lst[i+1] -= tmp

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

taoshita = 0
for i in range(n):
  taoshita += min(a[i], b[i])
  yoryoku = max(a[i]-b[i], 0)
  taoshita += min(a[i+1], yoryoku)
  a[i+1] = max(a[i+1]-yoryoku, 0)

print(taoshita)

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

taoshita = 0
for i in range(n):
  taoshita += min(a[i], b[i])
  yoryoku = max(b[i]-a[i], 0)
  taoshita += min(a[i+1], yoryoku)
  a[i+1] = max(yoryoku-a[i+1], 0)

print(taoshita)

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

taoshita = 0
for i in range(n):
  taoshita += min(a[i], b[i])
  yoryoku = max(b[i]-a[i], 0)
  taoshita += min(a[i+1], yoryoku)
  a[i+1] = max(a[i+1]-yoryoku, 0)

print(taoshita)

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())
monsters=list(map(int, input().split()))
battle=list(map(int, input().split()))
remain=0
win=0
for i in range(n):
    if remain != 0:
        win += remain
        battle[i] -= remain
        remain = 0
    if monsters[i] < battle[i]:
        win += monsters[i]
        monsters[i+1] -= battle[i] - monsters[i]
    else:
        win += battle[i]
        remain = monsters[i] - battle[i]
print(win)

n=int(input())
monsters=list(map(int, input().split()))
battle=list(map(int, input().split()))
remain=0
win=0
for i in range(n):
    if remain != 0:
        win += remai
        battle[i] -= remain
        remain = 0
    if monsters[i] < battle[i]:
        win += monsters[i]
        monsters[i+1] -= battle[i] - monsters[i]
    else:
        win += battle[i]
        remain = monsters[i] - battle[i]
print(win)

n=int(input())
monsters=list(map(int, input().split()))
battle=list(map(int, input().split()))
remain=0
win=0
for i in range(n):
    if monsters[i] < battle[i]:
        win += monsters[i]
        if monsters[i+1] >= battle[i] - monsters[i]:
            win += battle[i] - monsters[i]
            monsters[i+1] -= battle[i] - monsters[i]
        else:
            win += monsters[i+1]
            monsters[i+1] = 0
    else:
        win += battle[i]
print(win)

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

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

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


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

ans = 0

for i in range(n):
    
    tmp = a[i] - b[i]
    
    
    if tmp < 0 and -tmp <= a[i+1]:
        ans += b[i]
        a[i+1] += tmp
    
    elif tmp < 0 and -tmp > a[i+1]:
        ans += a[i]+a[i+1]
        a[i+1] = 0
    
    else:
        ans += 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):
#C - City Savers

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

for i in range(N):
  if A[i] <= B[i] + ad:
    count += A[i]
    ad = max(0, B[i] - max(A[i] - ad, 0))
    print(count, ad)
  else:
    count += B[i] + ad
    ad = 0
    print(count, ad)

count += min(A[N], ad)     

print(count)


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

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

count += min(A[N], ad)     

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=[int(x) for x in input().split()]
b=[int(x) for x in input().split()]
t=0

print(a)
print(b)

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

print(t)


n=int(input())
a=[int(x) for x in input().split()]
b=[int(x) for x in input().split()]
t=0

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

print(t)


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

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


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

kill = 0

if A[0] >= B[0]:
  kill += B[0]
  B[0] = 0
else:
  kill += A[0]
  B[0] -= A[0]

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

print(kill)

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

kill = 0

if A[0] >= B[0]:
  kill += B[0]
  B[0] = 0
else:
  kill += A[0]
  B[0] -= A[0]

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

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

kill = 0

if A[0] >= B[0]:
  kill += B[0]
  B[0] = 0
else:
  kill += A[0]
  B[0] -= A[0]

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

if A[N] <= B[N-1]:
  kill += A[N]
else:
  kill += B[N-1]

print(kill)

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


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 A[i] > B[i]:
        cnt += B[i]
        A[i] -= B[i]
        B[i] = 0
        
    else:
        cnt += A[i]
        B[i] -= A[i]
        A[i] = 0
        
            
    if A[i+1] > B[i]:
        cnt += B[i]
        A[i+1] -= B[i]
        B[i] = 0
        
    else:
        cnt += A[i+1]
        B[i] -= A[i+1]
        A[i+1] = 0

    #print(A)
    
    #print(cnt)
    #print('')
        
       
cnt += min(A[-1],B[-1]) 


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):
2
100 1 1
1 100

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

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

print(fenum - sum(A))


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

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

print(fenum - 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 = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
ans = 0
for i in range(n):
  if a[i] + a[i+1] <= b[i]:
    s += a[i] + a[i+1]
    a[i+1] = 0
  elif a[i] + a[i+1] > b[i] and a[i] <= b[i]:
    s += b[i]
    a[i+1] -= b[i] - a[i]
  elif a[i] > b[i]:
    s += a[i]
print(s)
    
    

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

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

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

monster_count = 0
next_saver = 0

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

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

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

monster_count = 0
next_saver = 0

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


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
def main():
    input = sys.stdin.readline

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

    res = 0
    for i in range(N):
        a = A[i]
        b = B[i]

        if a >= b:
            res += b
            A[i] = A[i] - b
        elif a < b:
            res += a
            A[i] = A[i] - a
            a_nx = A[i + 1]
            b -= a
            if a_nx >= b:
                res += b
                A[i + 1] = A[i + 1] - b
            elif a_nx < b:
                res += a_nx
                A[i + 1] = A[i + 1] - a_nx
    print(res)

if __name__ == '__main__':
    main()

import sys
def main():
    input = sys.stdin.readline

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

    res = 0
    for i in range(N):
        a = A[i]
        b = B[i]

        if a >= b:
            res += b
            A[i] = A[i] - b
        elif a < b:
            res += a
            A[i] = A[i] - a
            a_nx = A[i + 1]
            b -= a
            if a_nx >= b:
                res += b
                A[i + 1] = A[i + 1] - b
            elif a_nx < b:
                res += a_nx
                A[i + 1] = A[i + 1] - a_nx
    print(res)

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()))
i=0
count=0
while True:
    count+=min(a[i],b[i])
    if i==n:
        break
    elif a[i]>b[i]:
        i+=1
    else:
        c=b[i]-a[i]
        count+=min(a[i+1],c)
        if c>a:
            a[i+1]=0
            i+=1
        else:
            a[i+1]-=c
            i+=1
print(count)


n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
i=0
count=0
while True:
    count+=min(a[i],b[i])
    if i==n:
        break
    elif a[i]>b[i]:
        i+=1
    else:
        c=b[i]-a[i]
        count+=min(a[i+1],c)
        if c>a:
            a[i+1]=0
            i+=1
        else:
            a[i+1]-=c
            i+=1
print(count)


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


n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
b.append(0)
i=0
count=0
while True:
    if i==n+1:
        break
    elif a[i]>b[i]:
        i+=1
        count+=min(a[i],b[i])
    else:
        count+=min(a[i],b[i])
        c=b[i]-a[i]
        count+=min(a[i+1],c)
        if c>a[i+1]:
            a[i+1]=0
            i+=1
        else:
            a[i+1]-=c
            i+=1
print(count)


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

Verdicts: Runtime Error

Runtime Error

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())
Alist = list(map(int, input().split()))
Blist = list(map(int, input().split()))
amari = 0
ans = 0
for i in range(N):
    can_kill = amari + Blist[i]
    enemy = Alist[i]
    if can_kill > enemy:
        ans += enemy
        amari = max(Blist[i] - enemy, 0)
    else:
        ans += can_kill
        amari = 0
if amari > Alist[-1]:
    ans += Alist[-1]
else:
    ans += amari
print(ans)


N = int(input())
Alist = list(map(int, input().split()))
Blist = list(map(int, input().split()))
amari = 0
ans = 0
for i in range(N):
    can_kill = Blist[i]
    enemy = Alist[i]
    if can_kill > enemy:
        Alist[i] = 0
        ans += enemy
        amari = Blist[i] - enemy
    else:
        Alist[i] -= can_kill
        ans += can_kill
        amari = 0
    if Alist[i + 1] > amari:
        ans += amari
        Alist[i + 1] -= amari
    else:
        ans += Alist[i + 1]
        Alist[i + 1] = 0
    # print(Alist, ans)
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
data = sys.stdin.readline().split('\n')
twn = int(data[0]) + 1
ysh = int(data[0])
yshabl = list(map(int,data[2].split()))
mnstr = list(map(int,data[1].split()))

cnt = 0

for i in range(-1,-1*len(yshabl)-1,-1):
	y = yshabl[i]
	m = mnstr[i]+mnstr[i-1]
	if m >= y:
		cnt += y
		mnstr[i-1] -= y - mnstr[i]
	else:
		cnt += m
		mnstr[i-1] = 0

print(cnt)

n = int(input())
mnstr = list(map(int,input().split()))
yshabl = list(map(int,input().split()))

cnt = 0

for i in range(-1,-1*len(yshabl)-1,-1):
	y = yshabl[i]
	m = mnstr[i]+mnstr[i-1]
	if m >= y:
		cnt += y
		if mnstr[i] >= y:
			pass
		else:
			mnstr[i-1] -= y - mnstr[i]
	else:
		cnt += m
		mnstr[i-1] = 0

print(cnt)

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, mod = 0, 0

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

    if B[i] > A[i]:
        ans += A[i]
        mod = B[i] - A[i]
    else:
        ans += B[i]
        mod = 0

print(ans)


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

ans, mod = 0, 0

for i in range(N):

    if mod > A[i]:
        ans += A[i]
        A[i] = 0
    else:
        ans += mod
        A[i] -= mod
        mod = 0

    if B[i] > A[i]:
        ans += A[i]
        mod = B[i] - A[i]
    else:
        ans += B[i]
        mod = 0

ans += min(mod, 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):
a=[]
b=[]
ah=[]
bh=[]
c=int(input())
for x in input().split(" "):
    a.append(int(x))
for x in input().split(" "):
    b.append(int(x))

for x in a:
    ah.append(x)
for x in b:
    bh.append(x)

i=0
n=0

while i<c:
    if ah[i]>bh[i]:
        n+=bh[i]
        ah[i]=ah[i]-bh[i]
    else:
        n+=ah[i]
        ah[i]=0
        bh[i]-=ah[i]
        if ah[i+1]>bh[i]:
            n+=bh[i]
            ah[i+1]-=bh[i]
        else:
            n+=ah[i+1]
            ah[i+1]=0
    i+=1

print(n)

a=[]
b=[]
ah=[]
bh=[]
c=int(input())
for x in input().split(" "):
    a.append(int(x))
for x in input().split(" "):
    b.append(int(x))

"""for x in a:
    ah.append(x)
for x in b:
    bh.append(x)"""

ah=a
bh=b

i=0
n=0

while i<c:
    if ah[i]>bh[i]:
        n+=bh[i]
        ah[i]=ah[i]-bh[i]
    else:
        n+=ah[i]
        ah[i]=0
        bh[i]-=ah[i]
        if ah[i+1]>bh[i]:
            n+=bh[i]
            ah[i+1]-=bh[i]
        else:
            n+=ah[i+1]
            ah[i+1]=0
    i+=1

print(n)

a=[]
b=[]
ah=[]
bh=[]
c=int(input())
for x in input().split(" "):
    a.append(int(x))
for x in input().split(" "):
    b.append(int(x))

i=0
n=0

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

print(n)

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):
C:\acm\python\python.exe C:/acm/py/44.py
3
5 6 3 8
5 100 8
22
2
100 1 1
1 100
3
2
3 5 2
4 5
9


while True:
    try:
        sum=0
        n=eval(input())
        l1=list(map(int,input().split()))
        l2=list(map(int,input().split()))
        for i in range(n):
            ss=1
            if(l2[i]-l1[i]>0):
                s=l2[i]-l1[i]
                if l1[i+1]-s<0:
                    sum+=l1[i+1]
                    l1[i+1]=0
                else:
                    l1[i+1]-=s
                    sum+=s
                    sum+=l1[i]
                    ss=0
                if(ss!=0):sum+=l1[i]

            elif(l2[i]-l1[i]<=0):
                sum+=l2[i]
        print(sum)
    except:break

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):
#C
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
b.append(0)
m = [0 for _ in range(n+1)]
tmp = 0

for i in range(n+1):
    if tmp >= a[i]:
        m[i] += a[i]
        tmp = b[i]
        
    elif tmp < a[i]:
        if a[i] <= b[i]:
            b[i] -= a[i]
            m[i] += a[i]
            tmp = b[i]
        
        else:#a > b
            m[i] += b[i]
            b[i] = 0
            tmp = 0
     
     
print(sum(m))

#C
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
b.append(0)
m = [0 for _ in range(n+1)]
tmp = 0

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

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

ans = 0 

ta = A[-1]

for a, b in list(zip(A[:-1], B))[::-1]:
    print(ans, a,b,ta)
    tb = b
    if ta >= b:
        ans += b
        ta = a
        continue
    else:
        ans += ta
        tb -= ta
        ta = 0
        

    if a >= tb:
        ans += tb
        ta = a - tb
    else:
        ans += a
        ta = 0

print(ans)

# coding: utf-8

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

ans = 0 

ta = A[-1]

for a, b in list(zip(A[:-1], B))[::-1]:

    tb = b
    if ta >= b:
        ans += b
        ta = a
        continue
    else:
        ans += ta
        tb -= ta
        ta = 0
        

    if a >= tb:
        ans += tb
        ta = a - tb
    else:
        ans += a
        ta = 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):
#city savers
n=int(input())
ans=0
a=list(map(int,input().split()))
b=list(map(int,input().split()))
for i in range(n):
    if a[i]>=b[i]:
        ans+=b[i]
        a[i]-=b[i]
    else:
        
        ans+=a[i]
        a[i]=0
        b[i]-=a[i]
        if a[i+1]>=b[i]:
            ans+=b[i]
            a[i+1]-=b[i]
        else:
            
            ans+=a[i+1]
            a[i+1]=0
print(ans)

#city savers
n=int(input())
ans=0
a=list(map(int,input().split()))
b=list(map(int,input().split()))
for i in range(n):
    if a[i]>=b[i]:
        ans+=b[i]
        a[i]-=b[i]
    else:
        
        ans+=a[i]
        b[i]=b[i]-a[i]
        a[i]=0
        if a[i+1]>=b[i]:
            ans+=b[i]
            a[i+1]=a[i+1]-b[i]
 
        else:
            
            ans+=a[i+1]
            a[i+1]=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()))
count = 0
for i in range(N):
  if B[i] >= A[i]:
    s = B[i] - A[i]
    count += A[i]
    A[i] = 0
    if s >= A[i + 1]:
      count += A[i + 1]
      A[i + 1] = 0
    else:
      count += s
      A[i + 1] -= s
  else:
    count += B[i]
    A[i] -= B[i]

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

count = 0

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

print(count)

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

count = 0

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

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):
# coding: utf-8
# Your code here!
N=int(input())

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

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

print(A)
print(B)
print(count)



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

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

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

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

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

n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
 
ans = 0
for itr, b in enumerate(B):
  rem = b
  for i in range(2):
    dam = min(rem, A[itr + i])
    A[itr + i] -= dam
    ans += dam
    rem -= dam
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()]
print('OK')
su = sum(a)
a_len = len(a)
count = 0
i = 0
a_idx = 0
b_idx = 0
a_num = a[a_idx]
b_num = b[b_idx]
while(b_idx < n and a_idx <= a_len and count < su):
    
    a_num = a_num - 1
    
    if i == b_num:
        b_num = b[b_idx]
        b_idx += 1
        i = 0
    elif a_num == 0:
        a_num = a[a_idx]
        a_idx += 1
    count += 1
    i += 1
    


print(count)



n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
su = sum(a)
a_len = len(a)
count = 0
i = 0
a_idx = 0
b_idx = 0
a_num = a[a_idx]
b_num = b[b_idx]
while(count < su):
    
    a_num = a_num - 1
    
    if i == b_num:
        b_num = b[b_idx]
        b_idx += 1
        i = 0
        if b_idx == n:
            break
    if a_num == 0:
        a_num = a[a_idx]
        a_idx += 1
        if a_idx > a_len:
            break
    count += 1
    i += 1
    


print(count)


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

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

print(cnt)

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

ans = 0
remain = a[0]

for i in range(n):
    k = b[i] - remain
    if k <= 0:
        ans += b[i]
        remain = a[i+1]
    elif k > 0:
        if k >= a[i+1]:
            ans += remain + a[i+1]
            remain = 0
        elif k < a[i+1]:
            ans = b[i]
            remian = a[i+1] - k
    print(ans)

print(ans)

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

ini = sum(a)
ans = 0
remain = a[0]

for i in range(n):
    remain = max(0, b[i] - a[i])
    a[i] = max(0, a[i]-b[i])
    a[i+1] = max(0, a[i+1]-remain)

    
fin = sum(a)

print(ini-fin)

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 numpy as np
N = int(input())

A_ls = np.array(list(map(int,input().split(" "))))
B_ls = np.array(list(map(int,input().split(" "))))

S = 0

for i,b in B_ls:
    if b > A_ls[i]:
        A_ls[i] == 0
        b -= A_ls[i]
        S += A_ls[i]
        if A_ls[i+1] >= b:
            A_ls[i+1] -=b
            S+=b
        else:
            A_ls[i+1] = 0
            S+=(A_ls[i+1])
    else:
        S += b

print(S)



import numpy as np
N = int(input())

A_ls = np.array(list(map(int,input().split(" "))))
B_ls = np.array(list(map(int,input().split(" "))))

S = 0

for i,a in A_ls:
    if a > B_ls[i]:
        B_ls[i] == 0
        a -= B_ls[i]
        S += B_ls[i]
        if B_ls[i+1] >= a:
            B_ls[i+1] -=a
            S+=a
        elif:
            B_ls[i+1] = 0
            S+=(B_ls[i+1])
    elif:
        S += a

print(S)



import numpy as np
N = int(input())

A_ls = np.array(list(map(int,input().split(" "))))
B_ls = np.array(list(map(int,input().split(" "))))

S = 0

for i,b in enumerate(B_ls):
    if b > A_ls[i]:
        b -= A_ls[i]
        S += A_ls[i]
        if A_ls[i+1] >= b:
            A_ls[i+1] -=b
            S+=b
        else:
            S+=A_ls[i+1]
            A_ls[i+1] = 0 
    else:
        S += b

print(S)


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

n=int(input())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
asum=sum(a)
a1=a
ans=0
for i in range(n):
  if b[i]>=a1[i]+a1[i+1]:
    a1[i],a1[i+1]=0,0
    ans+=a1[i]+a1[i+1]
  elif b[i]>=a1[i]:
    a1[i+1]-=b[i]-a1[i]
    a1[i]=0
    ans+=b[i]
  else:
    a1[i]-=b[i]
    ans+=b[i]
print(asum-sum(a1))


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
    res = 0 
    for i in range(n):

        ch = min(a[i],res)
        cnt += ch
        a[i] -= ch
        if b[i] > a[i]:
            cnt += a[i]
            res = b[i] - a[i]
        else:
            cnt += b[i]
            res = 0
    
    cnt += min(a[n],res)

    print(cnt)


n = int(input())
h = [int(x) for x in input().split()]

flg=0
flg_0 = 0
for i in range(0,len(h)-1):
    tmp = h[i] - h[i+1]
    if(tmp >= 2)&(flg!=1):
        print("No")
        flg=1
    elif(tmp ==1):
        h[i] -= 1
        if(h[i-1]-h[i] >= 1)&(h[i] != 0)&(flg!=1):
            print("No")
            flg=1
            
if(flg!=1):
    print("Yes")
    


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

cnt = 0
res = 0 
for i in range(n):

    ch = min(a[i],res)
    cnt += ch
    a[i] -= ch
    if b[i] > a[i]:
        cnt += a[i]
        res = b[i] - a[i]
    else:
        cnt += b[i]
        res = 0

cnt += min(a[n],res)

print(cnt)

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

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

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):
2
100 1 1
1 100

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

Verdicts: Runtime Error

Accepted