TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: We have a sequence p = {p_1,\ p_2,\ ...,\ p_N} which is a permutation of {1,\ 2,\ ...,\ N}.  You can perform the following operation at most once: choose integers i and j (1 \leq i < j \leq N), and swap p_i and p_j. Note that you can also choose not to perform it.  Print `YES` if you can sort p in ascending order in this way, and `NO` otherwise.

Submission attempts (in order):
N = int(input())
P = [ int(s) for s in input().split() ]
P_S = sorted(P)

if sum(map(lambda x: x[0] != x[1], zip(P,P_S))) <= 2:
    print('Yes')
else:
    print('No')


N = int(input())
P = [ int(s) for s in input().split() ]
P_S = sorted(P)
 
if sum(map(lambda x: x[0] != x[1], zip(P,P_S))) <= 2:
    print('YES')
else:
    print('NO')

Verdicts: Wrong Answer

Accepted
Problem: We have a sequence p = {p_1,\ p_2,\ ...,\ p_N} which is a permutation of {1,\ 2,\ ...,\ N}.  You can perform the following operation at most once: choose integers i and j (1 \leq i < j \leq N), and swap p_i and p_j. Note that you can also choose not to perform it.  Print `YES` if you can sort p in ascending order in this way, and `NO` otherwise.

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

for i in range(N-1):
    if p[i] > p[i+1]:
        cnt += 1
        l.append(i)

if cnt > 2:
    print('NO')
if cnt < 2:
    print('YES')
if cnt == 2:
    p[l[0]], p[l[1]+1] = p[l[1]+1], p[l[0]]
    cnt = 0
    for i in range(N-1):
        if p[i] > p[i+1]:
            cnt += 1
            l.append(i)
    print(p)
    if cnt == 0:
        print('YES')
    else:
        print('NO')

N = int(input())
p = list(map(int, input().split()))
cnt = 0
l = list()

for i in range(N-1):
    if p[i] > p[i+1]:
        cnt += 1
        l.append(i)

if cnt <= 1:
    print('YES')
elif (cnt==2) and (p[l[0]-1] <= p[l[1]+1] <= p[l[0]+1]) and (p[l[1]] <= p[l[0]] <= p[l[1]+2]):
    print('YES')
else: print('NO')


N = int(input())
p = list(map(int, input().split()))
cnt = 0
l = list()

for i in range(N-1):
    if p[i] > p[i+1]:
        cnt += 1
        l.append(i)

if cnt > 2:
    print('NO')
if cnt == 1:
    print('NO')
if cnt == 0:
    print('YES')
if cnt == 2:
    p[l[0]], p[l[1]+1] = p[l[1]+1], p[l[0]]
    cnt = 0
    for i in range(N-1):
        if p[i] > p[i+1]:
            cnt += 1
            l.append(i)
    if cnt == 0:
        print('YES')
    else:
        print('NO')

Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: We have a sequence p = {p_1,\ p_2,\ ...,\ p_N} which is a permutation of {1,\ 2,\ ...,\ N}.  You can perform the following operation at most once: choose integers i and j (1 \leq i < j \leq N), and swap p_i and p_j. Note that you can also choose not to perform it.  Print `YES` if you can sort p in ascending order in this way, and `NO` otherwise.

Submission attempts (in order):
N = int(input())
p = [int(i) for i in input().split()]

cnt = 0
for i in range(0, N - 1):
    if p[i] > p[i + 1]:
        cnt += 1

print("YES" if cnt <= 1 else "NO")


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

array = [i for i in range(1, N + 1)]
cnt = 0

for i in range(N):
    if p[i] != array[i]:
        cnt += 1

print("YES" if cnt <= 2 else "NO")


Verdicts: Wrong Answer

Accepted
Problem: We have a sequence p = {p_1,\ p_2,\ ...,\ p_N} which is a permutation of {1,\ 2,\ ...,\ N}.  You can perform the following operation at most once: choose integers i and j (1 \leq i < j \leq N), and swap p_i and p_j. Note that you can also choose not to perform it.  Print `YES` if you can sort p in ascending order in this way, and `NO` otherwise.

Submission attempts (in order):
n=int(input())
p=[int(x) for x in input().split()]
pp=[int(x+1) for x in range(n)]

for i in range(n):
    buf=i+1
    if buf != p[i]:
        p[p.index(buf)]=p[i]
        p[i]=buf
        break

if pp==p:
    print("Yes")
else:
    print("No")

n=int(input())
p=[int(x) for x in input().split()]
pp=[int(x+1) for x in range(n)]

count=0

for i in range(n):
    if p[i]!=pp[i]:
        count+=1

if count <= 2
    print("Yes")
else:
    print("No")

n=int(input())
p=[int(x) for x in input().split()]
pp=[int(x+1) for x in range(n)]

count=0

for i in range(n):
    if p[i]!=pp[i]:
        count+=1

if count <= 2:
    print("Yes")
else:
    print("No")

n=int(input())
p=[int(x) for x in input().split()]
pp=[int(x+1) for x in range(n)]
 
for i in range(n):
    buf=i+1
    if buf != p[i]:
        p[p.index(buf)]=p[i]
        p[i]=buf
        break
 
if pp==p:
    print("YES")
else:
    print("NO")

Verdicts: Wrong Answer

Runtime Error

Wrong Answer

Accepted
Problem: We have a sequence p = {p_1,\ p_2,\ ...,\ p_N} which is a permutation of {1,\ 2,\ ...,\ N}.  You can perform the following operation at most once: choose integers i and j (1 \leq i < j \leq N), and swap p_i and p_j. Note that you can also choose not to perform it.  Print `YES` if you can sort p in ascending order in this way, and `NO` otherwise.

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

p = input().split()

p_sort = sorted(p)

count = 0
for i in range(N):
    if p[i]!=p_sort[i]: count+=1

if count > 2: print('No')
else: print('Yes')


N = int(input())

p = input().split()

p_sort = [i for i in range(1,N+1)]

count = 0
for i in range(N):
    if p[i]!=p_sort[i]: count+=1

if count > 2: print('NO')
else: print('YES')


N = int(input())

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

p_sort = [i for i in range(1,N+1)]

count = 0
for i in range(N):
    if p[i]!=p_sort[i]: count+=1

if count > 2: print('NO')
else: print('YES')


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

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

print(total)

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

print(total)


Verdicts: Wrong Answer

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

Submission attempts (in order):
import copy

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

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

print(ans)
    


import copy

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

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

print(ans)
    


Verdicts: Runtime Error

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

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

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

print(ans)


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

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

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

guchoku=0
for i,b in enumerate(B):
    t = A[i] - b
    if t <= -1:
        zen = min(A[i+1] - t, 0)
        guchoku += A[i+1] - zen
        A[i+1] = zen
    guchoku += min(A[i], b)
print(guchoku)


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

guchoku=0
for i,b in enumerate(B):
    t = A[i] - b
    if t <= -1:
        zen = max(A[i+1] + t, 0)
        guchoku += A[i+1] - zen
        A[i+1] = zen
    guchoku += min(A[i], b)
print(guchoku)


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

defeat = lambda Ai, Bi: min(A[i], B[i]) 

total = 0
for i in range(len(B)):
    num_of_defeated = defeat(A[i], B[i])
    A[i] -= num_of_defeated
    total += num_of_defeated

    remainder = B[i] - num_of_defeated
    num_of_defeated = defeat(A[i + 1], remainder)
    A[i + 1] -= num_of_defeated
    total += num_of_defeated

print(total)


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

defeat = lambda Ai, Bi: min(Ai, Bi) 

total = 0
for i in range(len(B)):
    num_of_defeated = defeat(A[i], B[i])
    A[i] -= num_of_defeated
    total += num_of_defeated

    remainder = B[i] - num_of_defeated
    num_of_defeated = defeat(A[i + 1], remainder)
    A[i + 1] -= num_of_defeated
    total += num_of_defeated

print(total)


Verdicts: Wrong Answer

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

Submission attempts (in order):
R = lambda: map(int, input().split())
input()
a = list(R())
def f():
    y = 0
    for u, v, w in zip(R(), a, a[1:]):
        x = min(v - y, u)
        y = x + min(w, u - x)
        yield x + y
print(sum(f()))


R = lambda: map(int, input().split())
input()
a = list(R())
def f():
    s = 0
    for x, y, z in zip(R(), a, a[1:]):
        t = min(x, y - s)
        s = min(z, x - t)
        yield s + t
print(sum(f()))


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

        a[i]=0

print(s-sum(a))

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

        a[i]=0

print(s-sum(a))

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

        a[i]=0

print(s-sum(a))

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

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

print(total)


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

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

print(total)


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

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

print(total)


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

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):
    for j in range(i,i+2):
        tmp = b[i]
        b[i] -= a[j]        
        if b[i]<=0:
            ans += tmp
            a[j] -= tmp
            break
        else:
            ans += a[j]
            a[j] = 0
            
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 = [int(x) for x in input().split(" ")]
b = [int(x) for x in input().split(" ")]


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

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


print(count)

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

if b[n-1] - a[n-1] > 0:
    count += a[n-1]
    rest = b[n-1] - a[n-1]
    if rest < a[n]:
        count += rest
    else:
        count += a[n]
else:
    count += b[n-1]


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):
num_lines = int(input())
if num_lines<1 or num_lines>10**5:
	print ('Illegal')
	exit()
#print(num_lines)
a=list(map(int,input().split(" ")))
b=list(map(int,input().split(" ")))

if len(a) !=num_lines +1 or len(b)!=num_lines:
	print ('Illegal')
	exit()

#print (a)

s=0
r=0
for i in range(num_lines):
	x=min(a[i]-r,b[i])
	s+=x
	r=0
	if(x<b[i]):
		y=min(a[i+1],b[i]-x)
		s+=y
		r=max(a[i+1]-y,0)
print(s)


num_lines = int(input())
if num_lines<1 or num_lines>10**5:
	print ('Illegal')
	exit()
#print(num_lines)
a=list(map(int,input().split(" ")))
b=list(map(int,input().split(" ")))

if len(a) !=num_lines +1 or len(b)!=num_lines:
	print ('Illegal')
	exit()

#print (a)

s=0
r=0
for i in range(num_lines):
	x=min(a[i]-r,b[i])
	s+=x
	r=0
	if(x<b[i]):
		y=min(a[i+1],b[i]-x)
		s+=y
		r=a[i+1]-y
print(s)


num_lines = int(input())
if num_lines<1 or num_lines>10**5:
	print ('Illegal')
	exit()
#print(num_lines)
a=list(map(int,input().split(" ")))
b=list(map(int,input().split(" ")))

if len(a) !=num_lines +1 or len(b)!=num_lines:
	print ('Illegal')
	exit()

#print (a)

s=0
r=0
for i in range(num_lines):
	x=min(a[i]-r,b[i])
	s+=x
	r=0
	if(x<b[i]):
		y=min(a[i+1],b[i]-x)
		s+=y
		r=y
print(s)


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())
An = map(int,input().split())
Bn = map(int,input().split())
ans=0
for b in range(len(Bn)):
    left = min(An[b],Bn[b])
    ans+=left
    An[b]-=left
    Bn[b]-=left
    right = min(An[b+1],Bn[b])
    ans+=right
    An[b+1]-=right
    Bn[b]-=right
print(ans)


N = int(input())
An = list(map(int,input().split()))
Bn = list(map(int,input().split()))
ans=0
for b in range(len(Bn)):
    left = min(An[b],Bn[b])
    ans+=left
    An[b]-=left
    Bn[b]-=left
    right = min(An[b+1],Bn[b])
    ans+=right
    An[b+1]-=right
    Bn[b]-=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()))
count = 0
for i in range(N):
  c1 = min(A[i], B[i])
  c2 = min(A[i+1], max(0, B[i]-A[i]))
  A[i+1] -= c2
  count += c1+c2

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
count = 0
for i in range(N):
  c1 = min(A[i], B[i])
  c2 = min(A[i+1], max(0, B[i]-A[i]))
  A[i+1] -= c2
  count += c1+c2
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())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))
bl.append(0)

mons = 0
b0 = 0

for a, b in zip(al, bl):
    if a >= (b0 + b):
        mons += b0 + b
    else:
        mons += a
        b0 = b - max(a-b, 0)

print(mons)

n = int(input())
al = list(map(int, input().split()))
bl = list(map(int, input().split())) + [0]
ans, tmp_b = 0, 0

for i in range(n+1):
    ans += min(al[i], tmp_b+bl[i])
    tmp_b = max(0, bl[i] - max(0, al[i]-tmp_b))
    # print(ans, tmp_b)

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
import numpy as np

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

accum_a = a[1:]+a[:-1]

filled = np.zeros(n+1, dtype=np.bool)
filled[:n][accum_a < b] = True
filled[1:][accum_a < b] = True
used = np.zeros(n, dtype=np.bool)
used[accum_a < b] = True
result = np.sum(filled*a)
result += np.sum(b*(1-used))
print(result)

import numpy as np

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


result = 0

for i in range(n):
    if a[i] <= b[i]:
        result += a[i]
        if a[i]+a[i+1] < b[i]:
            result += a[i+1]
            a[i+1] = 0
        else:
            diff = a[i]+a[i+1] - b[i]
            result += (a[i+1] - diff)
            a[i+1] = diff
    else:
        result += b[i]
        
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):
#!/usr/bin/env python
# coding: utf-8

# In[26]:


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


# In[27]:


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


# In[ ]:






#!/usr/bin/env python
# coding: utf-8

# In[26]:


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


# In[28]:


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


# In[ ]:






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

killed = 0
attack = 0
attack_l = [0, 0]
for i in range(0, n+1):
  if i != n:
    attack_l[i%2] = heros[i]
    attack = attack_l[0] + attack_l[1]
  if (monsters[i] - attack) < 0:
    killed += monsters[i]
    if (attack_l[0] - monsters[i]) >= 0:
      attack_l[0] = 0
    else:
      attack_l[1] = monsters[i] - attack_l[0]
      attack_l[0] = 0
  elif (monsters[i] - attack) > 0:
    killed += attack
    attack_l[0] = 0
    attack_l[1] = 0
  elif (monsters[i] - attack) == 0:
    killed += monsters[i]
    attack_l[0] = 0
    attack_l[1] = 0

print(killed)

n = int(input())
monsters = list(map(int, input().split()))
heros = list(map(int, input().split()))

killed = 0
attack = 0
attack_l = [heros[0], 0]
for i in range(0, n+1):
  if i != n and i != 0:
    attack_l[1] = heros[i]
  attack = attack_l[0] + attack_l[1]
  if (monsters[i] - attack) < 0:
    killed += monsters[i]
    if (attack_l[0] - monsters[i]) < 0:
      attack_l[1] -= monsters[i] - attack_l[0]
    attack_l[0] = attack_l[1]
    attack_l[1] = 0
  elif (monsters[i] - attack) > 0:
    killed += attack
    attack_l[0] = 0
    attack_l[1] = 0
  elif (monsters[i] - attack) == 0:
    killed += monsters[i]
    attack_l[0] = 0
    attack_l[1] = 0

print(killed)

n = int(input())
monsters = list(map(int, input().split()))
heros = list(map(int, input().split()))

killed = 0
attack = 0
attack_l = [heros[0], 0]
for i in range(0, n+1):
  if i != n and i != 0:
    attack_l[1] = heros[i]
  attack = attack_l[0] + attack_l[1]
  if (monsters[i] - attack) < 0:
    killed += monsters[i]
    if (attack_l[0] - monsters[i]) < 0:
      attack_l[1] = attack_l[1] - (monsters[i] - attack_l[0])
    attack_l[0] = attack_l[1]
    attack_l[1] = 0
  elif (monsters[i] - attack) > 0:
    killed += attack
    attack_l[0] = 0
    attack_l[1] = 0
  elif (monsters[i] - attack) == 0:
    killed += monsters[i]
    attack_l[0] = 0
    attack_l[1] = 0

print(killed)

n = int(input())
monsters = list(map(int, input().split()))
heros = list(map(int, input().split()))

killed = 0
attack = 0
attack_l = [0, heros[0]]
for i in range(0, n+1):
  if i != n and i != 0:
    attack_l[1] = heros[i]
  attack = attack_l[0] + attack_l[1]
  if (monsters[i] - attack) < 0:
    killed += monsters[i]
    if (attack_l[0] - monsters[i]) < 0:
      attack_l[1] += (attack_l[0] - monsters[i])
    attack_l[0] = attack_l[1]
    attack_l[1] = 0
  elif (monsters[i] - attack) > 0:
    killed += attack
    attack_l[0] = 0
    attack_l[1] = 0
  elif (monsters[i] - attack) == 0:
    killed += monsters[i]
    attack_l[0] = 0
    attack_l[1] = 0

print(killed)

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

A_0 = A_list.pop(0)
#print(A_0)
#print(A_list)
A_list[0] = A_list[0] + A_0
#print(A_list)

taos = 0
nokori = 0
keep = 0

for i, (a, b) in enumerate(zip(A_list, B_list)):
  if i == 0:
    if a >= b:
      taos += b
    else:
      taos += b-a
  else: 
    if (a + nokori) >= (b + keep) :
      taos += (b + keep)
      nokori = (a + nokori) - (b + keep)
      keep = 0
    else:
      taos += (a + nokori)
      nokori = 0
      keep = (b + keep) - (a + nokori)
 
print(taos)

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

taos = 0
keep = 0

for i, (a, b) in enumerate(zip(A_list, B_list)):
  if a >= (b + keep) :
    taos += (b + keep)
    keep = 0
  else:
    taos += a
    if keep > a:
      keep = b
    else:
      keep = (b + keep) - a 
  

if A_list[-1] >= keep:
  taos += keep
else:
  taos += A_list[-1]
print(taos)

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()))
num=0
for i in range(n):
  num+=min(a[i],b[i])
  b[i]=max(0,b[i]-a[i])
  num+=min(b[i]-a[i],a[i+1])
  a[i+1]=max(0,a[i+1]-b[i])
print(num)

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

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

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

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

def resolve():

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

    ans = 0

    for i in range(n):

        beat_now = min(a[i], b[i])
        ans += beat_now
        beat_next = min(a[i+1], b[i] - min(a[i], b[i]))
        ans += beat_next
        a[i+1] -= beat_next

    print(ans)

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

    ans = 0

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

    print(ans)


resolve()

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

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

ans = 0
x = 0
ans += min(A[0],B[0])

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

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

a = (int)(input())
mons = list(map(int, input().split(" ")))
yuu = list(map(int, input().split(" ")))
count = 0
for i in range(a):
  print(count)
  if yuu[i] >= mons[i]:
    yuu[i] -= mons[i]
    count += mons[i]
    if yuu[i] >= mons[i + 1]:
      yuu[i] -= mons[i + 1]
      count += mons[i + 1]
    else:
      mons[i + 1] -= yuu[i]
      count += yuu[i]
  else:
    mons[i] -= yuu[i]
    count += yuu[i]
print(count)

a = (int)(input())
mons = list(map(int, input().split(" ")))
yuu = list(map(int, input().split(" ")))
count = 0
for i in range(a):
  if yuu[i] >= mons[i]:
    yuu[i] -= mons[i]
    count += mons[i]
    mons[i] = 0
    if yuu[i] >= mons[i + 1]:
      yuu[i] -= mons[i + 1]
      count += mons[i + 1]
      mons[i + 1] = 0
    else:
      mons[i + 1] -= yuu[i]
      count += yuu[i]
  else:
    mons[i] -= yuu[i]
    count += yuu[i]
    mons[i] -= yuu[i]
print(count)

Verdicts: Wrong Answer

Wrong Answer

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

Submission attempts (in order):
N = int(input())
List_A = list(map(int, input().split()))
List_B = list(map(int, input().split()))
res = 0
for i in range(N-1):
  if List_A[i] >= List_B[i]:
    res += List_B[i]
  else:
    res += List_A[i]
    if List_A[i+1] >= List_B[i]-List_A[i]:
      res += List_B[i]-List_A[i]
      List_A[i+1] = List_A[i+1] - List_B[i] +List_A[i]
    else:
      res += List_A[i+1]
      List_A[i+1] = 0
print(res)

N = int(input())
List_A = list(map(int, input().split()))
List_B = list(map(int, input().split()))
res = 0
for i in range(N):
  if List_A[i] >= List_B[i]:
    res += List_B[i]
  else:
    res += List_A[i]
    if List_A[i+1] >= List_B[i]-List_A[i]:
      res += List_B[i]-List_A[i]
      List_A[i+1] = List_A[i+1] - List_B[i] +List_A[i]
    else:
      res += List_A[i+1]
      List_A[i+1] = 0
print(res)

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()))
sum_A = sum(A)
B = list(map(int,input().split()))
count = 0 


for i in range(N):
	count += i




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


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


print(sum_A - sum(A))


Verdicts: Wrong Answer

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

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

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

print(tot)


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

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

print(tot)



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

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

ans=0
right=0
left=0
for i in range(n):
    left=min(a[i],b[i])
    ans+=left
    a[i]-=left
    b[i]-=left
    
    right=min(a[i+1],b[i])
    ans+=right
    a[i+1]-=right
    b[i]-=right
print(ans)

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

ans=0
right=0
left=0
for i in range(n):
    left=min(a[i],b[i])
    ans+=left
    a[i]-=left
    b[i]-=left
    
    right=min(a[i+1],b[i])
    ans+=right
    a[i+1]-=right
    b[i]-=right
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):
def main():
  import sys
  n = int(input())
  a = list(map(int.sys.stdin.readline().split()))
  b = list(map(int.sys.stdin.readline().split()))
  
  count=0
  
  for i in range(n):
    c1 = a[i] 
    c2 = a[i+1]
    h = b[i]
    ans+=min(c1,h)  
    if h>c1:
        ans+=min(h-c1,c2)
        a[i+1]=max(0,c2-(h-c1))

  print(ans)
  
if __name__=="__main__":
  main()

def main():
  import sys
  n = int(input())
  a = list(map(int,sys.stdin.readline().split()))
  b = list(map(int,sys.stdin.readline().split()))
  
  count=0
  buffer=0
  
  for c,h in zip(a,b):
    count += min(buffer,c)
    g = max(0,c-buffer)
    count += min(h,g)
    buffer=max(0,h-g)
  else:
    count+=min(buffer,a[-1])
    
    
  print(count)
  
if __name__=="__main__":
  main()

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

N = int(input())
C = tuple(map(int,input().split()))
B = list(map(int,input().split()))
A = list(C)
for i in range(N)[::-1]:
    if A[i+1] > B[i]:
        A[i+1] -= B[i]
    elif B[i] < A[i]+A[i+1]:
        A[i] -= (B[i] - A[i+1])
        A[i+1] = 0
    else:
        A[i] = 0
        A[i+1] = 0
ans = 0
for j in range(N+1):
    ans += C[j]-A[j]
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):
def solve():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    maximum = sum(A)
    for i in reversed(range(N)):
        reduce2 = max(0, A[i + 1] - B[i])
        reduce1 = max(0, A[i] - B[i] + reduce2)
        A[i + 1] = reduce2
        A[i] = reduce1
    now = sum(A)

    print(maximum - now)


if __name__ == '__main__':
    solve()


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


if __name__ == '__main__':
    solve()


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

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

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


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

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

if (N == 1):
    print('Yes')
    exit()
hmax=H[0]
for i in range(N - 1):  
    if (hmax - H[i + 1]) > 1:
        print('No')
        exit()
    hmax = max(hmax, H[i + 1])
print('Yes')


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


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

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

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

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

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

ans = 0
for i in range(n):
    town_a = a[i]
    town_b = a[i+1]
    power = b[i]
    if power > town_a:
        ans += town_a
        power -= town_a
    else:
        ans += power
        continue
    if power > town_b:
        ans += town_b
        a[i+1] = 0
    else:
        ans += power
        a[i+1] -= power
print(ans)


Verdicts: Runtime Error

Accepted