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):
import sys
stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

N=int(input())
A=nl()
B=nl()
sumMb=sum(A)

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

print(sumMb-sum(A))


import sys
stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

N=int(input())
A=nl()
B=nl()
sumMb=sum(A)

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

print(sumMb-sum(A))

Verdicts: Wrong Answer

Accepted
Problem: There are N+1 towns. The i-th town is being attacked by A_i monsters.  We have N heroes. The i-th hero can defeat monsters attacking the i-th or (i+1)-th town, for a total of at most B_i monsters.  What is the maximum total number of monsters the heroes can cooperate to defeat?

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

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
c = A[0]
d = 0
for i in range(N):
    d += max(0, c - B[i])
    c = max(0, A[i+1] + min(0, c - B[i]))
    
print(sum(A) - (d + 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()))
#print("A=",A)


count = 0
for i in range(N+1):
    if i == 0:
        taosita = B[i]-max((B[i]-A[i]),0)
        count = taosita
        B[i]= B[i]-taosita
#        print("i=0")
    elif i!=N
        
        taosita1 = B[i-1]-max((B[i-1]-A[i]),0)
        count =count + taosita1
        A[i] = A[i]-taosita1
        
        taosita2 = B[i]-max((B[i]-A[i]),0)
        count =count + taosita2
        B[i]= B[i]-taosita2
    if i == N:
        
        taosita3 = B[i-1]-max((B[i-1]-A[i]),0)
        count =count + taosita3

print(count)

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


count = 0
for i in range(N+1):
    if i == 0:
        taosita = B[i]-max((B[i]-A[i]),0)
        count = taosita
        B[i]= B[i]-taosita
#        print("i=0")
    elif i!=N:
        
        taosita1 = B[i-1]-max((B[i-1]-A[i]),0)
        count =count + taosita1
        A[i] = A[i]-taosita1
        
        taosita2 = B[i]-max((B[i]-A[i]),0)
        count =count + taosita2
        B[i]= B[i]-taosita2
    if i == N:
        
        taosita3 = B[i-1]-max((B[i-1]-A[i]),0)
        count =count + taosita3

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):
#!/usr/bin/env python

N = input()
N = int(N)

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

B = []
B = input().split()
B = [int(n) for n in B]
B.append(0)
B.append(0)

#print('N=',n)
#print('A=',A)


monster = 0

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

print(monster)



#!/usr/bin/env python


N = input()
N = int(N)

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

B = []
B = input().split()
B = [int(n) for n in B]
B.append(0)

#print('N=',N)
#print('A=',A)


monster = 0

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

print(monster)









#!/usr/bin/env python

N = input()
N = int(N)

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

B = []
B = input().split()
B = [int(n) for n in B]
B.append(0)
B.append(0)

#print('N=',n)
#print('A=',A)


monster = 0

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

print(monster)



#!/usr/bin/env python

N = input()
N = int(N)

A = []
A = input().split()
A = [int(n) for n in A]
#A.append(0)

B = []
B = input().split()
B = [int(n) for n in B]
B.append(0)
#B.append(0)

#print('N=',n)
#print('A=',A)


monster = 0

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

print(monster)



Verdicts: Wrong Answer

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 = [int(a) for a in input().split()]
B = [int(b) for b in input().split()]
ans = 0
mons = 0
yusha = 0
for i in range(N):
	mons = max(A[i] - yusha, 0)
    ans += min(yusha, A[i])
    ans += min(mons, B[i])
    yusha = max(0, B[i] - mons)
print(ans)

N = int(input())
A = [int(a) for a in input().split()]
B = [int(b) for b in input().split()]
ans = 0
mons = 0
yusha = 0
for i in range(N):
    mons = max(A[i] - yusha, 0)
    ans += min(yusha, A[i])
    ans += min(mons, B[i])
    yusha = max(0, B[i] - mons)
ans += min(yusha, A[N])
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):
a = int(input())
b = list(map(int, input().split()))
c = list(map(int, input().split()))
d = 0
for i in range(a-1, -1, -1):
    d += min(b[i+1], c[i])
    b[i+1] -= min(b[i+1], c[i])
    c[i] -= min(b[i+1], c[i])

    d += min(b[i], c[i])
    b[i] -= min(b[i], c[i])
    c[i] -= min(b[i], c[i])
print(d)


a = int(input())
b = list(map(int, input().split()))
c = list(map(int, input().split()))
e = 0
for i in range(a):
    d = min(c[i], b[i])
    e += d
    c[i] -= d
    b[i] -= d
    d = min(c[i], b[i+1])
    e += d
    c[i] -= d
    b[i+1] -= d
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()))
c=0
for i in range(n-1):
  if a[i]<=b[i]:
    c+=a[i]
    d=b[i]-a[i]
    b[i+1]+=d
  else:
    c+=b[i]
if b[n-1]=>a[n-1]:
  c+=a[n-1]
  x=b[n-1]-a[n-1]
  c+=min(a[n],x)
else:
  c+=b[n-1]
print(c)

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

Verdicts: Runtime Error

Accepted
Problem: There are N+1 towns. The i-th town is being attacked by A_i monsters.  We have N heroes. The i-th hero can defeat monsters attacking the i-th or (i+1)-th town, for a total of at most B_i monsters.  What is the maximum total number of monsters the heroes can cooperate to defeat?

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

def cal(ans, n):
    ans += min(a[n], b[n])
    ans += b[n] - min(a[n], b[n])
    a[n+1] -= min(a[n], b[n])
        
for i in range(n):
    cal(ans,i)

print(ans)


import numpy as np
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a = np.array(a)
b = np.array(b)

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

    if ans == 0:
        print(np.sum(b))
        break

for i in range(n):
    if b[i]>0:
        ans += b[i]

print(ans)


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

def f(ans,n):
    nn = min(a[n], b[n])
    nnn = min(a[n+1], b[n] - nn)
    a[n+1] -= nnn
    ans += nn
    ans += nnn

for i in range(n):
    f(ans, i)

print(ans)


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

def f(n):
    nn = min(a[n], b[n])
    nnn = min(a[n+1], b[n] - nn)
    a[n+1] -= nnn
    return nn + nnn

for i in range(n):
    ans += f(i)

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


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

Verdicts: Wrong Answer

Accepted
Problem: There are N+1 towns. The i-th town is being attacked by A_i monsters.  We have N heroes. The i-th hero can defeat monsters attacking the i-th or (i+1)-th town, for a total of at most B_i monsters.  What is the maximum total number of monsters the heroes can cooperate to defeat?

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

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

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

power = 0
monster = 0
if A[0] > B[0]:
  reslut = B[0]
  kurikoshi = 0
else:
  reslut = A[0]
  kurikoshi = B[0] - A[0]  

for i in range(1, N):
  if A[i] - kurikoshi > 0:
    nokori = A[i] - kurikoshi
    result += kurikoshi
    if nokori > B[i]:
      result += B[i]
      kurikoshi = 0
    else:
      result += nokori
      kurikoshi = B[i] - nokori
  elif A[i] - kurikoshi <= 0:
    result += A[i]
    kurikoshi = B[i]
if A[N] > kurikoshi:
  result += kurikoshi
  print(result)
else:
  result += A[N]
  print(result)
  

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

if A[0] > B[0]:
  result = B[0]
  kurikoshi = 0
else:
  result = A[0]
  kurikoshi = B[0] - A[0]  

for i in range(1, N):
  if A[i] - kurikoshi > 0:
    nokori = A[i] - kurikoshi
    result += kurikoshi
    if nokori > B[i]:
      result += B[i]
      kurikoshi = 0
    else:
      result += nokori
      kurikoshi = B[i] - nokori
  elif A[i] - kurikoshi <= 0:
    result += A[i]
    kurikoshi = B[i]
if A[N] > kurikoshi:
  result += kurikoshi
  print(result)
else:
  result += A[N]
  print(result)
  

Verdicts: Runtime Error

Accepted
Problem: There are N+1 towns. The i-th town is being attacked by A_i monsters.  We have N heroes. The i-th hero can defeat monsters attacking the i-th or (i+1)-th town, for a total of at most B_i monsters.  What is the maximum total number of monsters the heroes can cooperate to defeat?

Submission attempts (in order):
def solv():
    n = int(input())
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    ans = 0

    for i in range(n+1):
        x = A[i] + A[i+1]
        ans += min(x,B[i])
        A[i+1] = min(A[i+1],max(x-B[i+1],0))
    print(ans)

solve()


def solv():
    n = int(input())
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    ans = 0

    for i in range(n+1):
        x = A[i] + A[i+1]
        ans += min(x,B[i])
        A[i+1] = min(A[i+1],max(x-B[i+1],0))
    return print(ans)

solv()


def solv():
    n = int(input())
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    ans = 0

    for i in range(n+1):
        x = A[i] + A[i+1]
        ans += min(x,B[i])
        A[i+1] = min(A[i+1],max(x-B[i+1],0))
    return print(ans)

solve()

def solv():
    n = int(input())
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    ans = 0

    for i in range(n):
        x = A[i] + A[i+1]
        ans += min(x,B[i])
        A[i+1] = min(A[i+1],max(x-B[i+1],0))
    return print(ans)

solv()


def solv():
    n = int(input())
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    ans = 0

    for i in range(n):
        x = A[i] + A[i+1]
        ans += min(x,B[i])
        A[i+1] = min(A[i+1],max(x-B[i],0))
    return print(ans)

solv()


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 = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]

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

print(cnt)

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

print(cnt)

Verdicts: Wrong Answer

Accepted
Problem: There are N+1 towns. The i-th town is being attacked by A_i monsters.  We have N heroes. The i-th hero can defeat monsters attacking the i-th or (i+1)-th town, for a total of at most B_i monsters.  What is the maximum total number of monsters the heroes can cooperate to defeat?

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

c = 0
for i in range(n):
      ci = 0
      ci = min(a[i],b[i])
      c += ci
      b[i] -= ci
      ci1 = 0
      ci1 = min(a[i+1],b[i])
      c += ci1
      c[i+1] -= ci1

print(c)


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

ans = 0
for i in range(n):
      ans += min(L2[i],L1[i]+L1[i+1])
      L1[i+1] = max(0,L1[i+1] - max(0,(L2[i]-L1[i])))
print(c)
                  

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

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

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

Verdicts: Runtime Error

Accepted
Problem: There are N+1 towns. The i-th town is being attacked by A_i monsters.  We have N heroes. The i-th hero can defeat monsters attacking the i-th or (i+1)-th town, for a total of at most B_i monsters.  What is the maximum total number of monsters the heroes can cooperate to defeat?

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

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

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

sum_M = []
for i in range(0, N+1):
 if i == 0:
  p1 = max(0, Y[0] - M[0])
  sum_M.append(min(M[0], Y[0]) ) 
 elif i < N:
  sum_M.append(min(M[i], Y[i] + p1) )
  p0 = 
  p1 = min(Y[i], max(0, Y[i] - (M[i] + p1)) )
 else:
  sum_M.append(min(M[i], p1) )
  p1 = max(0, p1 - M[i])  

print(sum(sum_M))


N = int(input())

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

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

sum_M = []
for i in range(0, N+1):
 if i == 0:
  p1 = max(0, Y[0] - M[0])
  sum_M.append(min(M[0], Y[0]) ) 
 elif i < N:
  sum_M.append(min(M[i], Y[i] + p1) )
  p1 = min(Y[i], max(0, Y[i] - (M[i] + p1)) )
 else:
  sum_M.append(min(M[i], p1) )
  p1 = max(0, p1 - M[i])  

print(sum(sum_M))


N = int(input())

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

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

sum_M = []
for i in range(0, N+1):
 if i == 0:
  p1 = max(0, Y[0] - M[0])
  sum_M.append(min(M[0], Y[0]) ) 
 elif i < N:
  sum_M.append(min(M[i], Y[i] + p1) )
  p1 = min(Y[i], max(0, Y[i] - M[i] + p1) )
 else:
  sum_M.append(min(M[i], p1) )
  p1 = max(0, p1 - M[i])  

print(sum(sum_M))


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

ans = 0
for i,b in enumerate(B):
    temp = min(b,A[i]+A[i+1])
    ans += temp
    A[i+1] -= max(0, temp-A[i]) 
print(an)


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

ans = 0
for i,b in enumerate(B):
    temp = min(b,A[i]+A[i+1])
    ans += temp
    A[i+1] -= max(0, temp-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):
# import itertools
# import math

import sys
input = sys.stdin.readline


def solve(N, A, B):
    defeat_monstar = 0
    for nn in range(N):
        if A[nn] >= B[nn]:
            defeat_monstar += B[nn]
        elif A[nn + 1] < (B[nn] - A[nn]):
            defeat_monstar += (A[nn + 1] + A[nn])
            A[nn + 1] = 0
        else:
            defeat_monstar += B[nn]
            A[nn + 1] = B[nn] - A[nn]

    return defeat_monstar


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

# P = []
# S = []

#     pp, ss = map(int, input().split())
#     P.append(pp)
#     S.append(ss)

print(solve(N, A, B))


# import itertools
# import math

import sys
input = sys.stdin.readline


def solve(N, A, B):
    defeat_monstar = 0
    for nn in range(N):
        if A[nn] >= B[nn]:
            defeat_monstar += B[nn]
        elif (A[nn + 1] + A[nn]) < B[nn]:
            defeat_monstar += (A[nn + 1] + A[nn])
            A[nn + 1] = 0
        else:
            defeat_monstar += B[nn]
            A[nn + 1] = B[nn] - A[nn]

    return defeat_monstar


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

# P = []
# S = []

#     pp, ss = map(int, input().split())
#     P.append(pp)
#     S.append(ss)

print(solve(N, A, B))


# import itertools
# import math

import sys
input = sys.stdin.readline


def solve(N, A, B):
    defeat_monstar = 0
    for nn in range(N):
        
        if A[nn] >= B[nn]:
            defeat_monstar += B[nn]
        else:
            B[nn] -= A[nn]
            
            if A[nn + 1] <= B[nn]:
                defeat_monstar += A[nn] + A[nn + 1]
                A[nn + 1] = 0
            else:
                A[nn + 1] = A[nn + 1] - B[nn]
                defeat_monstar += A[nn] + B[nn]

    return defeat_monstar


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

# P = []
# S = []

#     pp, ss = map(int, input().split())
#     P.append(pp)
#     S.append(ss)

print(solve(N, A, B))


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):
a = int(input())
b = list(map(int,input()))
c = list(map(int,input()))

ans = 0
for i in range(a):
  ans += min(b[i],c[i])
  c[i] -= min(b[i],c[i])
  ans += min(b[i + 1], c[i])

print(ans)
    

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

ans = 0
for i in range(a):
  ans += min(b[i],c[i])
  c[i] -= min(b[i],c[i])
  ans += min(b[i + 1], c[i])
  b[i + 1] -= min(b[i + 1], c[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())
monster = list(map(int, input().split()))
savers = list(map(int, input().split()))
first = sum(monster)
rest = []
for i in reversed(range(n)):
    monster_i = monster.pop()
    save_i = savers[i]
    
    monster_ii = max(monster_i - save_i, 0)
    
    save_ii = save_i - monster_ii
    rest.append(monster_ii)
    monster[-1] = max(monster[-1] - save_ii, 0)
ans = first - sum(rest) - monster[0]
print(ans)

n = int(input())
monster = list(map(int, input().split()))
savers = list(map(int, input().split()))
first = sum(monster)
rest = []
for i in reversed(range(n)):
    monster_i = monster.pop()
    save_i = savers[i]
    
    monster_ii = max(monster_i - save_i, 0)
    
    save_ii = save_i - (monster_i - monster_ii)
    rest.append(monster_ii)
    monster[-1] = max(monster[-1] - save_ii, 0)
ans = first - sum(rest) - monster[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 = input()
A = list(map(int, input().split()))
B = list(map(int, input().split()))

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

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

Verdicts: Runtime Error

Accepted
Problem: There are N+1 towns. The i-th town is being attacked by A_i monsters.  We have N heroes. The i-th hero can defeat monsters attacking the i-th or (i+1)-th town, for a total of at most B_i monsters.  What is the maximum total number of monsters the heroes can cooperate to defeat?

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

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

count = 0

for i in range(N):

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

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

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

print(defeat)

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

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

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

n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans = 0
for i in range(n):
    if b[i] <= a[i]:
        ans += b[i]
    elif b[i] <= a[i] + a[i+1]:
        a[i+1] = a[i+1] + a[i] - b[i]
        ans += b[i]
    else:
        ans += a[i] + 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):
import numpy as np
N = int(input())
A = [int(i) for i in input().split()] 
B = [int(i) for i in input().split()] 
C = np.zeros(N+1)
count = 0
for i in range(N):
  a = A[i] - B[i] -C[i]
  if a >= 0:
    count += B[i]
  else:
    count += A[i]
    if A[i] - C[i] < 0:
      C[i+1] = B[i]
    else:
      C[i+1] = -a
if C[N] > 0:
  if A[N] < C[N]:
    count += A[N]
  else:
    count += C[N]
print(int(count))
print(C)

import numpy as np
N = int(input())
A = [int(i) for i in input().split()] 
B = [int(i) for i in input().split()] 
C = np.zeros(N+1)
count = 0
for i in range(N):
  a = A[i] - B[i] -C[i]
  if a >= 0:
    count += B[i]
  else:
    count += A[i]
    C[i+1] = -a
if C[N] > 0:
  if A[N] < C[N]:
    count += A[N]
  else:
    count += C[N]
print(count)

import numpy as np
N = int(input())
A = [int(i) for i in input().split()] 
B = [int(i) for i in input().split()] 
C = np.zeros(N+1)
count = 0
for i in range(N):
  a = A[i] - B[i] -C[i]
  if a >= 0:
    count += B[i] + C[i]
  else:
    count += A[i]
    if A[i] - C[i] < 0:
      C[i+1] = B[i]
    else:
      C[i+1] = -a
if C[N] > 0:
  if A[N] < C[N]:
    count += A[N]
  else:
    count += C[N]
print(int(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):
from sys import stdin


def main():
    N = int(stdin.readline().rstrip())
    As = [int(x) for x in stdin.readline().rstrip().split()]
    Bs = [int(x) for x in stdin.readline().rstrip().split()]
    # result = 0

    print(sum(As))

    # if As[0] == 0 or Bs[0] == 0:
    
    # elif Bs[0] < As[0]:
    #     result += Bs[0]
    #     Bs[0] = 0
    # else:
    #     result += As[0]
    #     Bs[0] -= As[0]

    # if As[N] == 0 or Bs[N - 1] == 0:
    
    # elif Bs[N - 1] < As[N]:
    #     result += Bs[N - 1]
    #     Bs[N - 1] = 0
    # else:
    #     result += As[N]
    #     Bs[N - 1] -= As[N]

    
    #     a = As[i]
    #     b = Bs[i - 1]
    #     if a == 0 or b == 0:
    
    #     elif b < a:
    #         result += b
    #         Bs[i - 1] = 0
    #     else:
    #         result += a
    #         Bs[i - 1] -= a
    #     a = As[i]
    #     b = Bs[i]
    #     if a == 0 or b == 0:
    
    #     elif b < a:
    #         result += b
    #         Bs[i] = 0
    #     else:
    #         result += a
    #         Bs[i] -= a

    # print(result)


if __name__ == "__main__":
    main()


from sys import stdin


def main():
    _ = int(stdin.readline().rstrip())
    As = [int(x) for x in stdin.readline().rstrip().split()]
    Bs = [int(x) for x in stdin.readline().rstrip().split()]
    result = 0
    for i, b in enumerate(Bs):
        min_ = min(As[i], b)
        result += min_
        As[i] -= min_
        b -= min_

        min_ = min(As[i + 1], b)
        result += min_
        As[i + 1] -= min_
    print(result)


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):
import sys
sys.setrecursionlimit(100000)
input=sys.stdin.readline
def intinput():return map(int,input().split())


n=int(input())
a=list(intinput())
b=list(intinput())
ans=0
print(a)
for i in range(n):
    if a[i]+a[i+1]<b[i]:
        ans+=a[i]+a[i+1]
        a[i+1]=0
        print(a,0)
    else:
        ans+=b[i]
        a[i+1]-=0 if a[i]-b[i]>0 else b[i]-a[i]
        print(a,1)
print(ans)

import sys
sys.setrecursionlimit(100000)
input=sys.stdin.readline
def intinput():return map(int,input().split())


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

Verdicts: Runtime Error

Accepted
Problem: There are N+1 towns. The i-th town is being attacked by A_i monsters.  We have N heroes. The i-th hero can defeat monsters attacking the i-th or (i+1)-th town, for a total of at most B_i monsters.  What is the maximum total number of monsters the heroes can cooperate to defeat?

Submission attempts (in order):
n=int(input())
As=list(map(int,input().split()))
Bs=list(map(int,input().split()))
Bs.append(0)

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

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

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


n=int(input())
As=list(map(int,input().split()))
Bs=list(map(int,input().split()))
Bs.append(0)

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

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: There are N+1 towns. The i-th town is being attacked by A_i monsters.  We have N heroes. The i-th hero can defeat monsters attacking the i-th or (i+1)-th town, for a total of at most B_i monsters.  What is the maximum total number of monsters the heroes can cooperate to defeat?

Submission attempts (in order):
import copy
from itertools import accumulate
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

OA = copy.deepcopy(A)

#print(M)

#print(SM)


#print()

count = 0
for i in range(N):
    nokori = A[i] - B[i]
    if A[i] - B[i] >= 0 :
        count += nokori
    else :
        A[i + 1] -= abs(nokori)
        if A[i + 1] < 0 :
            A[i + 1] = 0
print(sum(OA) - count + A[N])

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

taoshi_count = 0
for i in range(N):
    nokori = A[i] - B[i]
    if A[i] - B[i] >= 0 :
        taoshi_count += B[i]
    else :
        taoshi_count += A[i]
        nokori_power = abs(nokori)
        if A[i + 1] >= nokori_power :
            taoshi_count += nokori_power
            A[i + 1] -= nokori_power
        else :
            taoshi_count += A[i + 1]
            A[i + 1] = 0
print(taoshi_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())
M = list(map(int, input().split()))
H = list(map(int, input().split()))

sum_m = 0
rest = 0
for i in range(0, N):
  killed = min(H[i], M[i]-rest)
  rest = max(0, H[i]+rest-M[i])
  sum_m = killed
sum_m += min(rest, M[-1])

print(sum_m)


N = int(input())
M = list(map(int, input().split()))
H = list(map(int, input().split()))

sum_m = 0
killed = 0
rest = 0
for i in range(0, N):
  killed = min(H[i], M[i]-rest)
  rest = max(0, H[i]-killed)
  sum_m += killed
sum_m += min(rest, M[-1])
print(sum_m)


N = int(input())
M = list(map(int, input().split()))
H = list(map(int, input().split()))

sum_m = 0
rest = 0
rest = max(0, H[1]-M[1])
sum_m += min(H[1], M[1])
for i in range(1, N):
  rest = max(0, H[i]+rest-M[i])
  if M[i] >= H[i]+rest:
    sum_m += H[i]+rest
  else:
    sum_m += M[i]
sum_m += min(rest, M[-1])

print(sum_m)


N = int(input())
M = list(map(int, input().split()))
H = list(map(int, input().split()))

sum_m = 0
rest = 0
for i in range(N):
  if M[i] >= H[i]+rest:
    sum_m += H[i]+rest
    rest = 0
  else:
    sum_m += M[i]
    rest = min(H[i], H[i]+rest-M[i])
sum_m += min(rest, M[-1])

print(sum_m)


Verdicts: Wrong Answer

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

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

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

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

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):
    if a[i] - b[i] >= 0:
        ans += b[i]
    else:
        if a[i+1] > b[i] - a[i]:
            ans += b[i]
            a[i+1] = a[i+1] - b[i] - a[i]
        else:
            ans += a[i+1] + a[i]
            a[i+1] = 0
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] >= 0:
        ans += b[i]
    else:
        if a[i+1] > b[i] - a[i]:
            ans += b[i]
            a[i+1] -= b[i] - a[i]
        else:
            ans += a[i+1] + a[i]
            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=([int(n) for n in input().split()])
b=([int(n) for n in input().split()])
b.append(0)
r=0
t=0
x=0
for i in range(n+1):
  t=b[i]+x-a[i]
  if t>=0:
    r=r+a[i]
    x=max(b[i],t)
  else:
    r=r+b[i]+x
    x=0
print(r)

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

Verdicts: Wrong Answer

Accepted
Problem: There are N+1 towns. The i-th town is being attacked by A_i monsters.  We have N heroes. The i-th hero can defeat monsters attacking the i-th or (i+1)-th town, for a total of at most B_i monsters.  What is the maximum total number of monsters the heroes can cooperate to defeat?

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

ans=0

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

print(ans)

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

ans=0

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

A_copy = [x for x in A]
B_copy = [y for y in B]
for i in range(N-1, -1, -1):
  if A_copy[i+1] > 0:
    A_copy[i+1] = max(A_copy[i+1]-B[i], 0)
    B_copy[i] = max(B_copy[i]-A[i+1], 0)
  if B_copy[i] > 0:
    a = A_copy[i]
    A_copy[i] = max(A_copy[i]-B_copy[i], 0)
    B_copy[i] = max(B_copy[i]-a, 0)

n = sum(A) - sum(A_copy)
print(n)

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

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

n = sum(B) - sum(B_copy)
print(n)

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

A_copy = [x for x in A]
B_copy = [y for y in B]
cnt = 0
for i in range(N-1, -1, -1):
  if A_copy[i+1] > 0:
    cnt += min(A_copy[i+1], B_copy[i])
    A_copy[i+1] = max(A_copy[i+1]-B[i], 0)
    B_copy[i] = max(B_copy[i]-A[i+1], 0)
  if B_copy[i] > 0:
    cnt += min(A_copy[i], B_copy[i])
    a = A_copy[i]
    A_copy[i] = max(A_copy[i]-B_copy[i], 0)
    B_copy[i] = max(B_copy[i]-a, 0)

n = sum(A) - sum(A_copy)
print(cnt)

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

A_copy = [x for x in A]
B_copy = [y for y in B]

for i in range(N-1, -1, -1):
  if A_copy[i+1] >= B_copy[i]:
    A_copy[i+1] -= B_copy[i]
    B_copy[i] = 0
  else:
    B_copy[i] -= A_copy[i+1]
    A_copy[i+1] = 0
    if A_copy[i] > B_copy[i]:
      A_copy[i] -= B_copy[i]
      B_copy[i] = 0
    else:
      B_copy[i] -= A_copy[i]
      A_copy[i] = 0

    #A_copy[i+1] = max(A_copy[i+1]-B[i], 0)
    #B_copy[i] = max(B_copy[i]-A[i+1], 0)
  #if B_copy[i] > 0:
   # a = A_copy[i]
    #A_copy[i] = max(A_copy[i]-B_copy[i], 0)
    #B_copy[i] = max(B_copy[i]-a, 0)

n = sum(B) - sum(B_copy)
print(n)

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: There are N+1 towns. The i-th town is being attacked by A_i monsters.  We have N heroes. The i-th hero can defeat monsters attacking the i-th or (i+1)-th town, for a total of at most B_i monsters.  What is the maximum total number of monsters the heroes can cooperate to defeat?

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

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

print(ans)


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

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

print(ans)


Verdicts: Runtime Error

Accepted
Problem: There are N+1 towns. The i-th town is being attacked by A_i monsters.  We have N heroes. The i-th hero can defeat monsters attacking the i-th or (i+1)-th town, for a total of at most B_i monsters.  What is the maximum total number of monsters the heroes can cooperate to defeat?

Submission attempts (in order):
n = int(input())
monster = list(map(int,input().split()))
brave = list(map(int,input().split()))
ans = 0
for i in range(n):
  if i == 0:
    kill = min(monster[0],brave[0])
    ans += kill 
    brave -= kill
  else:
    kill = min(monster[i],brave[i])
    ans += kill
    brave[i] -= kill
    kill = min(monster[i+1],brave[i])
    ans += kill
    monster -= kill
print(ans)
    

n = int(input())
monster = list(map(int,input().split()))
brave = list(map(int,input().split()))
ans = 0
for i in range(n):
  if i == 0:
    kill = min(monster[0],brave[0])
    ans += kill 
    brave[0] -= kill
  else:
    kill = min(monster[i],brave[i])
    ans += kill
    brave[i] -= kill
    kill = min(monster[i+1],brave[i])
    ans += kill
    monster[i+1] -= kill
print(ans)
    

n = int(input())
monster = list(map(int,input().split()))
brave = list(map(int,input().split()))
ans = 0
for i in range(n):
  kill = min(monster[i],brave[i])
  ans += kill
  brave[i] -= kill
  kill = min(monster[i+1],brave[i])
  ans += kill
  monster[i+1] -= kill
print(ans)
    

Verdicts: Runtime Error

Wrong Answer

Accepted