Problem:


Score : 300 points

Problem Statement

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?

Constraints

All values in input are integers.

1 \leq N \leq 10^5

1 \leq A_i \leq 10^9

1 \leq B_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_{N+1}
B_1 B_2 ... B_N

Output

Print the maximum total number of monsters the heroes can defeat.

Sample Input 1

2
3 5 2
4 5

Sample Output 1

9

If the heroes choose the monsters to defeat as follows, they can defeat nine monsters in total, which is the maximum result.

The first hero defeats two monsters attacking the first town and two monsters attacking the second town.

The second hero defeats three monsters attacking the second town and two monsters attacking the third town.

Sample Input 2

3
5 6 3 8
5 100 8

Sample Output 2

22

Sample Input 3

2
100 1 1
1 100

Sample Output 3

3



Sample input:
2
3 5 2
4 5


Sample output:
9

Submission status: Wrong Answer

Solution code:
def elip():
    return map(int,input().split())
N = int(input())
A = list(elip())
B = list(elip())
kill = 0
for i in range(len(B)):
    if A[i] != 0 and B[i] >= A[i]:
        B[i] -= A[i]
        kill += A[i]
        A[i] = 0
    else:
        A[i] -= B[i]
        kill += B[i]
        B[i] = 0
        continue
    if A[i+1] != 0 and B[i] >= A[i+1]:
        B[i] -= A[i+1]
        kill += A[i+1]
        A[i+1] = 0
    else:
        A[i] -= B[i]
        kill += B[i]
        B[i] = 0
print(kill)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

p = 0
result = 0

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

if a[n] < p:
    result += a[n]
else:
    result += p
        
print(result)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
death = 0
tmp = 0
for i,x in enumerate(b):
    if i == 0:
        death += min(a[i]+a[i+1],b[i])
    else:
        death += min(tmp+a[i+1],b[i])
    if (a[i]+a[i+1])<b[i]:
        tmp = 0
    else:
        if a[i]>b[i]:
            tmp = a[i+1]
        else:
            tmp = a[i]+a[i+1]-b[i]
print(death)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
death = 0
tmp = 0
for i,x in enumerate(b):
    if i == 0:
        death += min(a[i]+a[i+1],b[i])
    else:
        death += min(tmp+a[i+1],b[i])
    if (a[i]+a[i+1])<b[i]:
        tmp = 0
    else:
        tmp = a[i]+a[i+1]-b[i]
print(death)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

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

A.reverse()
B.reverse()

tmp = 0
counter = 0
for i in range(len(A)):
    #print(counter)
    if i == len(A)-1:
        counter += tmp
        continue

    if A[i] >= tmp:
        extra = A[i] - tmp
        counter += tmp
    else:
        counter += A[i]
        tmp = B[i]
        continue

    if extra >= B[i]:
        tmp = 0
        counter += B[i]
    else:
        tmp = B[i] - extra
        counter += extra
print(counter)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

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

A.reverse()
B.reverse()

tmp = 0
counter = 0
for i in range(len(A)):
    #print(counter)
    if i == len(A)-1:
        counter += tmp
        continue

    if A[i] > tmp:
        extra = A[i] - tmp
        counter += tmp
    else:
        counter += A[i]
        tmp = B[i]
        continue

    if extra >= B[i]:
        tmp = 0
        counter += B[i]
    else:
        tmp = B[i] - extra
        counter += extra
print(counter)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

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

A.reverse()
B.reverse()

tmp = 0
counter = 0
for i in range(len(A)):
    #print(counter)
    if i == len(A)-1:
        counter += tmp
        continue

    if A[i] > tmp:
        extra = A[i] - tmp
        counter += tmp
    else:
        counter += A[i]
        tmp = B[i]
        continue

    if extra > B[i]:
        tmp = 0
        counter += B[i]
    else:
        tmp = B[i] - extra
        counter += extra
print(counter)

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

Solution code:
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:
        B[i] -= A[i]
        ans += A[i]
        if A[i+1] >= B[i]:
            ans += B[i]
        else:
            ans += A[i+1]
            A[i+1] = 0
print(ans)

Submission status: Wrong Answer

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

k=0

for i in range(n):

  if a[i]<b[i]:
    k+=a[i]
    b[i]=b[i]-a[i]
    a[i]=0

    if a[i+1]<b[i]:
      k+=a[i+1]
      b[i]=b[i]-a[i+1]
      a[i+1]=0
    else:
      k+=b[i]
      b[i]=0
      a[i+1]=a[i+1]-b[i]

  else:
    k+=b[i]
    b[i]=0
    a[i]=a[i]-b[i]

print(k)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
d = []
for i in range(n):
    d.append([b[i],i])
d.sort(reverse=True)
count = 0
for i in range(n):
  x = a[d[i][1]] + a[d[i][1]+1]
  if d[i][0] >= x:
    a[d[i][1]] = 0
    a[d[i][1]+1] = 0
    count += x
  elif a[d[i][1]] != 0 or a[d[i][1]+1] !=0:
    val = x - d[i][0]
    count += d[i][0]
    a[d[i][1]] = 0
    a[d[i][1]+1] = val
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
count = 0
for i in range(n):
  x = a[i] + a[i+1]
  if b[i] >= x:
    b[i] = 0
    a[i] = 0
    a[i+1] = 0
    count += x
for i in range(n):
  x = a[i] + a[i+1]
  if b[i] >= x:
    b[i] = 0
    a[i] = 0
    a[i+1] = 0
    count += x
for i in range(n):
  if b[i] != 0:
    if a[i] != 0 or a[i+1] !=0:
      val = a[i] + a[i+1] - b[i]
      count += b[i]
      a[i] = 0
      a[i+1] = val
      b[i] = 0
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
count = 0
for i in range(n):
  x = a[i] + a[i+1]
  if b[i] >= x:
    b[i] = 0
    a[i] = 0
    a[i+1] = 0
    count += x
for i in range(n):
  if b[i] != 0:
    if a[i] != 0 or a[i+1] !=0:
      val = a[i] + a[i+1] - b[i]
      count += b[i]
      a[i] = 0
      a[i+1] = val
      b[i] = 0
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
list_A = list(map(int,input().split()))
list_B = list(map(int,input().split()))
beaten = 0 
for i in range(n):
  if list_A[i]<=list_B[i]:
    list_B[i] -= list_A[i]
    print(list_B[i])
    a = min(list_B[i],list_A[i+1])
    list_A[i+1] -= a
    beaten += a+list_A[i]
  else:
    beaten += list_B[i]
print(beaten)

Submission status: Wrong Answer

Solution code:
n =int(input())
a =list(map(int ,input().split()))
b =list(map(int ,input().split()))
b.append(0)
c =0
d =0
enemy =0
for i in range(len(a)):
    if a[i] >b[i] +c:
        d += a[i] -(b[i]+c)
    elif a[i] <=b[i] +c:
        c =0
        c =b[i]+c -a[i]

for i in range(len(a)):
    enemy +=a[i]       
print(enemy -d)

Submission status: Wrong Answer

Solution code:
n =int(input())
a =list(map(int ,input().split()))
b =list(map(int ,input().split()))
b.append(0)
c =0
d =0
enemy =0
for i in range(len(a)):
    if a[i] >b[i] +c:
        d += a[i] -(b[i]+c)
    elif a[i] <=b[i] +c:
        c =b[i]+c -a[i]

for i in range(len(a)):
    enemy +=a[i]       
print(enemy -d)

Submission status: Wrong Answer

Solution code:
n =int(input())
a =list(map(int ,input().split()))
b =list(map(int ,input().split()))
b.append(0)
c =0
d =0
enemy =0
for i in range(len(a)):
    if a[i] >b[i] +c:
        d += a[i] -(b[i]+c)
    elif a[i] <b[i] +c:
        c =b[i]+c -a[i]
for i in range(len(a)):
    enemy +=a[i]       
print(enemy -d)

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

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

kill_cnt += min(B[N-1],A[N-1]+A[N])
print(kill_cnt)

Submission status: Wrong Answer

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

kill_cnt += min(B[N-1],A[N-1]+A[N])
print(kill_cnt)

Submission status: Wrong Answer

Solution code:
#C - City Savers

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

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

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

print(count)

Submission status: Wrong Answer

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

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

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

print(count)

Submission status: Wrong Answer

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

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

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

print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
ene = list(map(int,input().split()))
power = list(map(int,input().split()))
ans=0
for i in range(n-1):
  ans+=min(power[i],ene[i])
  if ene[i]<power[i]:
    power[i+1]+=(power[i]-ene[i])
ans+=min(power[-1],ene[-2])
if power[-1]>ene[-2]:
  ans+=min(ene[-1],(power[-1]-ene[-2]))
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
kill = 0

for i in range(n):
    for j in range(i,i+2):
        if b[i] <= a[j]:
            kill += b[i]
            a[j] -= b[i]
            break
        else:
            kill += a[j]
            b[i] -= a[j]

print(kill)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
kill = 0

for i in range(n):
    for j in range(i,i+2):
        if b[i] <= a[j]:
            kill += b[i]
            a[j] -= b[i]
            continue
        else:
            kill += a[j]
            b[i] -= a[j]

print(kill)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
total  = 0
dif = 0
"""
for i in range(n):
    if a[i] > dif:
        a[i] -= dif
        total += dif   
        if a[i] >= b[i]:
            total += b[i]
        else:
            total += a[i]
            dif = b[i]-a[i]
    else:
        total += a[i]
        dif = b[i]
"""
for i in range(n):
    if a[i] > b[i]:
        total += b[i]
        a[i] -= b[i]
    else:
        total += a[i]
        b[i] -= a[i]

    if a[i+1] > b[i]:
        total += b[i]
        a[i+1] -= b[i]
    else:
        total += a[i+1]
        a[i+1] = 0
   

print(total)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
total  = 0
dif = 0
for i in range(n):
    if a[i] > dif:
        a[i] -= dif
        total += dif   
        if a[i] >= b[i]:
            total += b[i]
        else:
            total += a[i]
            dif = b[i]-a[i]
    else:
        total += a[i]
        dif = b[i]

print(total+min(dif,a[-1]))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [i for i in map(int,input().split())]
B = [i for i in map(int,input().split())]
ans = 0
for i in range(N):
    K = A[i:i+2]
    K.sort()
    K.reverse()
    Attack = B[i]
    for el in K:
        Used = []
        if Attack > 0:
            ans += min(Attack,el)
            if min(Attack,el) == Attack:
                break
            else:
                Attack -= el
                Used.append(el)
    for el in Used:
        m = A.index(el)
        A[m] = 0
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
res = 0
for i in range((n + 1)//2):
  if B[i] > A[i]:
    res += min(A[i] + A[i+1], B[i])
    A[i+1] = max(0, A[i] + A[i+1] - B[i])
    A[i] = 0
  else:
    res += B[i]
    A[i] -= B[i]
  if B[n-i-1] > A[n-i]:
    res += min(A[n-i] + A[n-i-1], B[n-i-1])
    A[n-i-1] = max(0, A[n-i-1] + A[n-i] - B[n-i-1])
    A[n-i] = 0
  else:
    res += B[n-i-1]
    A[n-i] -= B[n-i-1]
print(res)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n = ii()
A = iil()
B = iil()
rep = 0
ans = 0
for i,item in enumerate(B):
    ans += min(A[i],item+rep)
    rep = max(0, item - (A[i] - rep))
print(ans+min(A[-1],rep))

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
B.append(0)
ans = 0
num = 0
for i in range(n+1):
  if num != 0:
    if A[i] - num <= 0:
      num = B[i]
      ans += A[i]
    else:
      A[i] -= num
      num = 0
      if A[i] >= B[i]:
        num = 0
        ans += B[i]
      else:
        num = B[i]-A[i]
        ans += A[i]
  else:
    if A[i] >= B[i]:
      num = 0
      ans += B[i]
    else:
      num = B[i]-A[i]
      ans += A[i]
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.reverse()
b.reverse()
remain = 0
counter = 0
for i in range(n):
    counter += min(a[i], b[i] + remain)
    added = max(0, a[i] - remain)
    remain = max(0, b[i] - added)
counter += min(a[0], remain)
print(counter)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    B = [int(i) for i in input().split()]
    A2 = A[:]
    B2 = 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]
            else:
                ans += B[i]
                A[i+1] -= B[i]
        else:
            ans += B[i]
    ans2 = 0
    for i in range(N)[::-1]:
        if A2[i+1] < B2[i]:
            B2[i] -= A2[i+1]
            ans2 += A2[i+1]
            if A2[i] < B2[i]:
                ans2 += A2[i]
                A2[i] = 0
            else:
                ans2 += B2[i]
                A2[i] -= B2[i]
        else:
            ans2 += B2[i]
    print(max(ans, ans2))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    B = [int(i) for i in input().split()]
    ans = 0
    for i in range(N):
        if A[i] < B[i]:
            B[i] -= A[i]
            ans += A[i]
            if A[i+1] < B[i]:
                ans += A[i+1]
            else:
                ans += B[i]
                A[i+1] -= B[i]
        else:
            ans += B[i]
    ans2 = 0
    for i in range(N)[::-1]:
        if A[i+1] < B[i]:
            B[i] -= A[i+1]
            ans2 += A[i+1]
            if A[i] < B[i]:
                ans2 += A[i]
            else:
                ans2 += B[i]
                A[i] -= B[i]
        else:
            ans2 += B[i]
    print(max(ans, ans2))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    B = [int(i) for i in input().split()]
    ans = 0
    for i in range(N):
        if A[i] < B[i]:
            B[i] -= A[i]
            ans += A[i]
            if A[i+1] < B[i]:
                ans += A[i+1]
            else:
                ans += B[i]
                A[i+1] -= B[i]
        else:
            ans += B[i]
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
ans = 0
for i in range(N):
    if a[i]<=b[i]:
        ans += a[i]
        a[i] = 0
        if a[i+1]<=(b[i]-a[i]):
            ans += a[i+1]
            a[i+1]=0
        else:
            ans += (b[i]-a[i])
            a[i+1] = a[i+1]-(b[i]-a[i])
    else:
        ans += b[i]
        a[i] = a[i]-b[i]
        
print(ans)

Submission status: Wrong Answer

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

ans, mod = 0, 0

for i in range(N):

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

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

ans += min(mod, A[i])

print(ans)

Submission status: Wrong Answer

Solution code:
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] = 0, b[i]-a[i]
        a[i+1] -= b[i]
    else:
        a[i] -= b[i]
print(x-sum(a))

Submission status: Wrong Answer

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

ans, mod = 0, 0

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

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
m=list(map(int,input().split()))
c=list(map(int,input().split()))
ans=0

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

Submission status: Wrong Answer

Solution code:
n=int(input())
m=list(map(int,input().split()))
c=list(map(int,input().split()))
ans=0

for i in range(n-1,-1,-1):
  if m[i+1]>c[i]:
    ans+=c[i]
  elif m[i+1]<=c[i]<m[i]+m[i+1]:
    ans+=c[i]
    m[i]=m[i]+m[i+1]-c[i]
  else:
    ans+=m[i]+m[i+1]
    c[i]=0
  
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
m=list(map(int,input().split()))
c=list(map(int,input().split()))
ans=0

for i in range(n-1,-1,-1):
  if m[i+1]>=c[i]:
    ans+=c[i]
  elif m[i+1]<c[i]<m[i]+m[i+1]:
    ans+=c[i]
    m[i]=m[i]+m[i+1]-c[i]
  elif c[i]>=m[i]+m[i+1]:
    ans+=m[i]+m[i+1]
    c[i]=0
  
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = 0
for i in range(N):
    try:
        if A[i] <= B[i]:
            ans += A[i]
            B[i+1] += B[i] - A[i]
        else:
            ans += B[i]
    except IndexError:
        ans += min(B[i] - A[i], A[i+1])
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin

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

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

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

print(sumMb-sum(A))

Submission status: Wrong Answer

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

dp = [0]*N #勇者が倒す数

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n = int(input()) # 入力が1つ
# map(int, input().split()) # 入力が複数
m = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]

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

Submission status: Wrong Answer

Solution code:
def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

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


resolve()

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
t=0
y=[0]

for i in range(n):

    if a[i]-y[i] >= b[i]:
        
        t += b[i]
        y.append(0)
    
    elif a[i]-y[i]+a[i+1] <= b[i]:
        t += a[i]-y[i]+a[i+1]
        y.append(a[i+1])
    else:
        t += b[i]
        y.append(b[i]-a[i])

print(t)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
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 >= (b + b0):
        mons += (b + b0)
    else:
        mons += a
        b0 = max(0, b-(a-b0))

print(mons)

Submission status: Wrong Answer

Solution code:
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)