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

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

al = [int(i) for i in input().split()]
bl = [int(i) for i in input().split()]

ans = 0
for i in range(n):
    if bl[i] <= al[i]:
        ans += bl[i]
    elif bl[i] > al[i] and bl[i] <= al[i] + al[i+1]:
        ans += bl[i]
        al[i+1] = al[i] + al[i+i] - bl[i]
    else:
        ans += al[i] + al[i+1]
        al[i+1] = 0
        
print(ans)
        

n = int(input())

al = [int(i) for i in input().split()]
bl = [int(i) for i in input().split()]

ans = 0
for i in range(n):
    if bl[i] <= al[i]:
        ans += bl[i]
    elif bl[i] > al[i] and bl[i] <= al[i] + al[i+1]:
        ans += bl[i]
        al[i+1] = al[i] + al[i+i] - bl[i]
    else:
        ans += al[i] + al[i+1]
        al[i+1] == 0
        
print(ans)
        

n = int(input())

al = [int(i) for i in input().split()]
bl = [int(i) for i in input().split()]

ans = 0
for i in range(n):
    if al[i] > bl[i]:
        ans += bl[i]
    elif al[i] + al[i+1] > bl[i]:
        ans += al[i] + al[i+1]
        al[i+1] = 0
    else:
        ans += bl[i]
        al[i+1] = al[i+1] + al[i] - bl[i]
        
print(ans)  

n = int(input())
al = [int(i) for i in input().split()]
bl = [int(i) for i in input().split()]

ans = 0
for i in range(n):
    if al[i] > bl[i]:
        ans += bl[i]
    elif al[i] + al[i+1] > bl[i]:
        ans += bl[i]
        al[i+1] = al[i+1] + al[i] - bl[i]
    else:
        ans += al[i] + al[i+1]
        al[i+1] = 0
        
print(ans)  

Verdicts: Runtime Error

Runtime Error

Wrong Answer

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

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

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

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

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

    print(maxCount)


n = int(input())

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

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

print(maxCount)


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()))
pre=sum(A)

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

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

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

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

for i in range(N):
  if B[i]<=A[i]:
    A[i]-=B[i]
  else:
    A[i+1]=max(0, A[i+1]-B[i]+A[i])
    A[i]=0
print(pre-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):
    print(i)
    if A[i] > B[i]:
        ans += B[i]
        A[i] -= B[i]
        B[i] -= B[i]
    else:
        ans += A[i]
        B[i] -= A[i]
        A[i] -= A[i]
    if A[i+1] > B[i]:
        ans += B[i]
        A[i+1] -= B[i]
        B[i] -= B[i]
    else:
        ans += A[i+1]
        B[i] -= A[i+1]
        A[i+1] -= A[i+1]
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]
        A[i] -= B[i]
        B[i] -= B[i]
    else:
        ans += A[i]
        B[i] -= A[i]
        A[i] -= A[i]
    if A[i+1] > B[i]:
        ans += B[i]
        A[i+1] -= B[i]
        B[i] -= B[i]
    else:
        ans += A[i+1]
        B[i] -= A[i+1]
        A[i+1] -= A[i+1]
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):
 = 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]:
    ab = b[i] - a[i]
    if a[i+1] > ab:
      ans += b[i]
      a[i+1] -= ab
    else:
      ans += a[i] + a[i+1]
      a[i+1] = 0
  else:
    ans += b[i]

print(ans)


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

Verdicts: Runtime Error

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

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


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


Verdicts: Wrong Answer

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

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

sumbuster = 0
for i in range(n):
    ibuster=0
    j = i
    ibuster += min(b[i],a[j]+a[j+1])
    print(ibuster)
    if(b[i] >= (a[j]+a[j+1])):
        a[j+1] = 0
    sumbuster += ibuster

print(sumbuster)

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

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

print(buster)

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

 for i in range(N):
     if monstors[i] >= heros[i]:
         monstors[i] -= heros[i]
         heros[i] = 0
     else:
         heros[i] -= monstors[i]
         monstors[i] = 0
     if monstors[i+1] >= heros[i]:
         monstors[i+1] -= heros[i]
         heros[i] = 0
     else:
         heros[i] -= monstors[i+1]
         monstors[i+1] = 0
 print(init_monstor - sum(monstors))

N = int(input())
monstors = [int(i) for i in input().split()]
heros = [int(i) for i in input().split()]
init_monstor = sum(monstors)

for i in range(N):
    if monstors[i] >= heros[i]:
        monstors[i] -= heros[i]
        heros[i] = 0
    else:
        heros[i] -= monstors[i]
        monstors[i] = 0
    if monstors[i+1] >= heros[i]:
        monstors[i+1] -= heros[i]
        heros[i] = 0
    else:
        heros[i] -= monstors[i+1]
        monstors[i+1] = 0
print("{}".format(init_monstor - sum(monstors)))

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

A_list.reverse()
B_list.reverse()

killed_enemies = 0
killed_num = 0
for i in range(N):
    if killed_num + B_list[i] >= A_list[i]:
        killed_num = (killed_num + B_list[i]) - A_list[i]
        killed_enemies += A_list[i]

    else:
        killed_num = killed_num + B_list[i]
        killed_enemies += killed_num

if B_list[N-1] >= A_list[N]:
    killed_enemies += A_list[N]
else:
    killed_enemies += B_list[N-1]

print(killed_enemies)



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

A_list.reverse()
B_list.reverse()

killed_enemies = 0
killed_num = 0
for i in range(N+1):
    if i < N:
        if killed_num + B_list[i] >= A_list[i]:
            killed_num = (killed_num + B_list[i]) - A_list[i]
            killed_enemies += A_list[i]

        else:
            killed_num = killed_num + B_list[i]
            killed_enemies += killed_num
    else:
        if B_list[i-1] >= A_list[i]:
            killed_enemies += A_list[i]
        else:
            killed_enemies += B_list[i-1]

print(killed_enemies)



n = int(input())
AL = list(map(int, input().split()))
BL = list(map(int, input().split()))
ans = 0
for i in range(n):
    if BL[i] <= AL[i]:
        ans += BL[i]
    elif BL[i] > AL[i] and BL[i] <= AL[i]+AL[i+1]:
        ans += BL[i]
        AL[i+1] = AL[i+1] - BL[i] + AL[i]
    else:
        ans += AL[i]+AL[i+1]
        AL[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()))
count=0
print(a)
print(b)
def battle(a,ai,b):
  if a+ai <= b:
    count=a+ai
    ai=0
  elif a<=b:
    ai=ai-(b-a)
    count=b
  else:
    ai=ai
    count=b
  return ai,count
  
for i in range(n):
  c=0
  a[i+1],c=battle(a[i],a[i+1],b[i])
  count += c
 
print(count)

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

def battle(a,ai,b):
  if a+ai <= b:
    ai=0
    count=a+ai
  elif a<=b:
    ai=ai-(b-a)
    count=b
  else:
    ai=ai
    count=b
  result ai,count
  
for i in range(n):
  c=0
  a[i+1],c=battle(a[i],a[i+1],b[i])
  count += c

print(count)

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


Verdicts: Wrong Answer

Runtime Error

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

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

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

    ans_list = [0] * (n+1)
    rest_hero = 0
    for i in range(n+1):
        if i == n:
            now_hero = rest_hero
        else:
            now_hero = rest_hero + heroes[i]
        if now_hero >= monsters[i]:
            ans_list[i] = monsters[i]
            rest_hero = now_hero - monsters[i]
        else:
            ans_list[i] = now_hero
            rest_hero = 0
    ans = sum(ans_list)
    print(ans)


    print()


if __name__ == '__main__':
    main()


def main():
    n = int(input())
    monsters = [int(x) for x in input().split()]
    heroes = [int(x) for x in input().split()]

    sum_monsters = sum(monsters)
    for i in range(n-1, -1, -1):
        if monsters[i+1] >= heroes[i]:
            monsters[i+1] -= heroes[i]
            heroes[i] = 0
        else:
            temp_m = monsters[i+1]
            monsters[i+1] = 0
            heroes[i] -= temp_m
            if monsters[i] >= heroes[i]:
                monsters[i] -= heroes[i]
                heroes[i] = 0
            else:
                temp_m = monsters[i]
                monsters[i] = 0
                heroes[i] -= temp_m

    ans = sum_monsters - sum(monsters)
    print(ans)


if __name__ == '__main__':
    main()


Verdicts: Wrong Answer

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

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

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

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

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


Verdicts: Runtime Error

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

Submission attempts (in order):
def main():
    num_monster = 0
    res = 0  
    for i in range(N):
        a = A[i] - res  
        b = B[i]
        if b <= a:  
            num_monster += b
            res = 0
        elif b <= a+A[i+1]:  
            num_monster += b
            res = b - a
        else:  
            num_monster += a+A[i+1]
            res = A[i+1]
    print(num_monster)
main()

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

sum_ = 0
rest = 0

for i in range(n):
  if a[i] >= b[i] + rest:
    sum_ += b[i] + rest
    rest = 0
  elif a[i] >= rest:
    sum_ += a[i]
    rest = b[i]
  else:
    sum_ += a[i]
    rest = b[i]

sum_ += min(a[n], rest)
print(sum_)

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

sum_ = 0
rest = 0

for i in range(n):
  if a[i] >= b[i] + rest:
    sum_ += b[i] + rest
    rest = 0
  elif a[i] >= rest:
    sum_ += a[i]
    rest = b[i] - (a[i]- rest)
  else:
    sum_ += a[i]
    rest = b[i]

sum_ += min(a[n], rest)
print(sum_)

Verdicts: Wrong Answer

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

Submission attempts (in order):
def calc(a, b, c):
    if a < b:
        b -= a 
        c += a 
        a = 0 
    else:
        a -= b 
        c += b 
        b = 0
    return a, b, c 

c = 0
for i in reversed(range(N)):
    A[i+1], B[i], c = calc(A[i+1], B[i], c)
    A[i], B[i], c = calc(A[i], B[i], c)

print(c)

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

def calc(a, b, c):
    if a < b:
        b -= a 
        c += a 
        a = 0 
    else:
        a -= b 
        c += b 
        b = 0
    return a, b, c 

c = 0
for i in reversed(range(N)):
    A[i+1], B[i], c = calc(A[i+1], B[i], c)
    A[i], B[i], c = calc(A[i], B[i], c)

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

n=int(input())

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

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

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

counter =[]
for i,Bi in enumerate(B):
  counter.append(Bi-A[i]-A[i+1])
  
ID=counter.index(max(counter))
#print(ID)

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

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

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

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


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

i_i = lambda: int(i_s())
i_l = lambda: list(map(int, stdin.readline().split()))
i_s = lambda: stdin.readline().rstrip()

N = i_i()
A = i_l()
B = i_l()

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

print(ans)


import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)

i_i = lambda: int(i_s())
i_l = lambda: list(map(int, stdin.readline().split()))
i_s = lambda: stdin.readline().rstrip()

N = i_i()
A = i_l()
B = i_l()

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

    if A[i] < B[i]:
        if A[i+1] >= B[i] - A[i]:
            ans += B[i] - A[i]
            A[i+1] = A[i+1] - (B[i] -A[i])
        else:
            ans += A[i+1]
            A[i+1] = 0

print(ans)


Verdicts: Wrong Answer

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

Submission attempts (in order):
N=int(input())
a=input().split()
b=input().split()
for i in range(0,N):
  a[i]=int(a[i])
  b[i]=int(b[i])
a[N]=int(a[N])
answer=sum(a)
for i in range(0,N):
    c=b[i]-a[i]
    if c<0:
        a[i]=-c
        b[i]=0
    else:
        a[i]=0
        b[i]=c
    d=b[i]-a[i+1]
    if d<0:
        a[i+1]=-c
        b[i]=0
    else:
        a[i+1]=0
        b[i]=c
print (answer-sum(a))

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

for i in range(n):
  c += min(a[i],b[i])
  tmp = min(a[i+1],b[i]-min(a[i],b[i]))
  c += tmp
  if tmp == a[i+1]:
    del a[i+1]
    a.insert(i+1,0)
  else:
    del a[i+1]
    a.insert(i+1,a[i+1]+a[i]-b[i])

print(c)

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

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


Verdicts: Runtime Error

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=2
a=list(map(int, input().split()))  
#a = [100, 1, 1]
b=list(map(int, input().split()))  
#b=[1,100]
ans = 0

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

n=int(input())  
#n=2
a=list(map(int, input().split()))  
#a = [100, 1, 1]
b=list(map(int, input().split()))  
#b=[1,100]
ans = 0

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


def main():
    N = int(input())
    A = list(map(int, input().split()))

    for i in range(N):
        b = int(input())
        tmp = A[i] - b
        if tmp < 0:
            ans += A[i]
            if A[i + 1] < -tmp:
                ans += A[i + 1]
                A[i + 1] = 0
            else:
                ans += -tmp
                A[i + 1] += tmp
        else:
            ans += b

    print(ans)

if __name__ == "__main__":
    main()


# coding: utf-8


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

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

    print(ans)

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

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

Verdicts: Wrong Answer

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

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

answer = 0

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

        if A[i] < B[i-1]:
            answer += A[i]
            B[i-1] -= A[i]
            A[i] = 0

        else:
            answer += B[i-1]
            A[i] -= B[i-1]
            B[i-1] = 0

    else:
        if A[i] < B[i] + B[i-1]:
            answer += A[i]
            if A[i] < B[i-1]:
                B[i-1] -= A[i]
                A[i] = 0
            else:
                B[i-1] = 0
                B[i] -= (A[i]-B[i-1])
                A[i] = 0
        else:
            answer += (B[i]+B[i-1])
            A[i] -= (B[i]+B[i-1])
            B[i],B[i-1] = 0,0

print(answer)

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

answer = 0

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

        if A[i] < B[i-1]:
            answer += A[i]
            B[i-1] -= A[i]
            A[i] = 0

        else:
            answer += B[i-1]
            A[i] -= B[i-1]
            B[i-1] = 0

    else:
        if A[i] < B[i] + B[i-1]:
            answer += A[i]
            if A[i] < B[i-1]:
                B[i-1] -= A[i]
                A[i] = 0
            else:
                B[i] -= (A[i]-B[i-1])
                B[i-1] = 0
                A[i] = 0
        else:
            answer += (B[i]+B[i-1])
            A[i] -= (B[i]+B[i-1])
            B[i],B[i-1] = 0,0

print(answer)

Verdicts: Wrong Answer

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

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





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

print(sum(A))

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










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


ans -= sum(A)
print(ans)

Verdicts: Wrong Answer

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

Submission attempts (in order):
#135c
N = str(input())
list_A = list(map(int, input().split()))
list_B = list(map(int, input().split()))

#print("#################################################")

ans = 0
remaining_power = 0

if N>1:
    for i in range(N-1,-1,-1):
        

        if remaining_power>list_A[i+1]:
            
            remaining_power=list_B[i]
            ans += list_A[i+1]
            #print("margin")
        elif remaining_power + list_B[i] > list_A[i+1]:
            
            remaining_power = list_B[i] - (list_A[i+1] - remaining_power)
            ans += list_A[i+1]
            #print("OK")
        else:
            
            ans += remaining_power + list_B[i]
            remaining_power = 0
            #print("No")
else:
    remaining_power = list_B[0] 
            
if remaining_power > list_A[0]:
    ans += list_A[0]
else:
    ans += remaining_power
        
print(ans)

#135c
N = int(input())
list_A = list(map(int, input().split()))
list_B = list(map(int, input().split()))
 
#print("#################################################")
 
ans = 0
remaining_power = 0
 
if N>1:
    for i in range(N-1,-1,-1):
        
 
        if remaining_power>list_A[i+1]:
            
            remaining_power=list_B[i]
            ans += list_A[i+1]
            #print("margin")
        elif remaining_power + list_B[i] > list_A[i+1]:
            
            remaining_power = list_B[i] - (list_A[i+1] - remaining_power)
            ans += list_A[i+1]
            #print("OK")
        else:
            
            ans += remaining_power + list_B[i]
            remaining_power = 0
            #print("No")
else:
    remaining_power = list_B[0] 
            
if remaining_power > list_A[0]:
    ans += list_A[0]
else:
    ans += remaining_power
        
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
X = A[-1]
for i in range(N):
  if A[i] >= B[i]  and A[i] >= 0:
    count += B[i]
  elif A[i] < B[i] and A[i] >= 0:
    A[i+1] = A[i+1] - (B[i] - A[i])
    count += A[i]
if A[-1] >= 0:
  count += X - A[N+1]
else:
  count += X
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]  and A[i] >= 0:
    count += B[i]
    A[i] = A[i] - B[i]
  elif A[i] < B[i] and A[i] >= 0:
    if A[i+1]-B[i]+A[i] > 0:
      count += B[i]
    else:
      count += A[i] +A[i+1]
    A[i+1] = -1
    A[i] = -1
  elif A[i] < 0:
    if A[i+1] >= B[i]:
      count += B[i]
      A[i+1] = A[i+1]- B[i]
    else:
      count += A[i+1]
      A[i+1] -= B[i]
print(count)

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

Verdicts: Runtime Error

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

print(cnt)

n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans = min(a[0], b[0])
tmp = max(0, b[0]-a[0])

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

ai = A[0]
ai2 = A[1]

for i in range(N):

  bi = B[i]
  
  if ai <= bi:
    cnt += ai
    
    if ai2 <= (bi - ai):
      cnt += ai2
      ai = max(0, ai2-(bi - ai))
      ai2 = A[i+2]
    else:
      cnt += (bi - ai)
      ai = max(0, ai2-(bi - ai))
      ai2 = A[i+2]
      
  else:
    cnt += bi
    ai = A[i+1]
    ai2 = A[i+2]
  
print(int(cnt))

N = int(input())

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

A.append(0)
A.append(0)

ai = A[0]
ai2 = A[1]

for i in range(N):

  bi = B[i]
  
  if ai <= bi:
    cnt += ai
    
    if ai2 <= (bi - ai):
      cnt += ai2
      ai = max(0, ai2-(bi - ai))
      ai2 = A[i+2]
    else:
      cnt += (bi - ai)
      ai = max(0, ai2-(bi - ai))
      ai2 = A[i+2]
      
  else:
    cnt += bi
    ai = A[i+1]
    ai2 = A[i+2]
  
print(int(cnt))


Verdicts: Runtime Error

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

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

result = 0
beated = min(a[0],b[0])
result += beated

for i in range(1, n):
    beated = min(a[i],b[i]-beated)
    result += beated
print(result)

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

result = 0
for i in range(n):
    beated_l = min(a[i],b[i])
    beated_r = min(a[i+1],b[i]-beated_l)
    result += beated_l + beated_r
    a[i+1] -= beated_r
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):
#coding: UTF-8

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

Ans = 0

for num in range(N):
    Ans += min(A[num], B[num])
    if A[num] => B[num]:
        pass
    else: # A[num] < B[num]
        B[num] -= A[num]
        Ans += min(A[num+1], B[num])
        if A[num+1] => B[num]:
            A[num+1] -= B[num]
        else:
            A[num+1] = 0
print(Ans)

#coding: UTF-8

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

Ans = 0

for num in range(N):
    Ans += min(A[num], B[num])
    if A[num] >= B[num]:
        pass
    else: # A[num] < B[num]
        B[num] -= A[num]
        Ans += min(A[num+1], B[num])
        if A[num+1] >= B[num]:
            A[num+1] -= B[num]
        else:
            A[num+1] = 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 = list(map(int, input().split()))
B = list(map(int, input().split()))
A.reverse()
B.reverse()
ans = 0
t = A[0]
for a, b in zip(A[1:], B):
    t += a
    print(ans, t)
    m = min(t, b)
    ans += m
    t = t - m if t - a <= b else a

print(ans)


N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A.reverse()
B.reverse()
ans = 0
t = A[0]
for a, b in zip(A[1:], B):
    t += a
    m = min(t, b)
    ans += m
    t = t - m if t - a <= b else a

print(ans)


Verdicts: Wrong Answer

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

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

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

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

ans = 0
for i in range(N+1):
  taosukazu1 = min(A[i],B[i])
  B[i] -= taosukazu1
  A[i] -= taosukazu1
  ans += taosukazu1
  if B[i] > 0:
    taosukazu2 = min(A[i+1],B[i])
    B[i] -= taosukazu2
    A[i+1] -= taosukazu2
    ans += taosukazu2
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()))
x=sum(a)
for i in range(n):
  if a[i]>=b[i]:
    a[i]-=b[i]
  else:
    a[i]=0
    a[i+1]-=b[i]-a[i]
print(x-sum(a))

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

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()))
m=0
t=len(B)
for i in range(t)
if a[i]>=b[i]:
  m+=b[i]
  if a[i]-b[i]>=b[i+1]:
    m+=b[i+1]
    b[i+1]=0
  else:
    m+=a[i]-b[i]
    b[i+1]-=a[i]-b[i]
else:
  m+=a[i]
  

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

Verdicts: Runtime Error

Accepted