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:
import numpy as np
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a = np.array(a)
b = np.array(b)

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

cal(ans)

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

cal(ans)

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

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
N = N+1
monsters = list(map(int, input().split()))
heros = list(map(int, input().split()))
stack = 0
count = 0
point = 0
for i in range(0, len(heros)):
    point = monsters[i] - (stack + heros[i])
    if point < 0:
        if abs(point) > monsters[i+1]:
            stack = monsters[i+1]
        else:
            stack = abs(point)
        count += monsters[i]
    else:
        count += heros[i]
count += stack
print(count)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
for i in range(n):
    enemies = a[i] + a[i+1]
    heros = b[i]
    if enemies >= heros:
        ans += heros
    else:
        ans += enemies
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

i = N - 1
k = 0

while i >= 0:

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

    i -= 1

print(k)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc135/tasks/abc135_c
import numpy as np


def calc(N: int, A: np.ndarray, B: np.ndarray) -> int:
    remain_A = A[:-1].copy()
    remain_B = B.copy()

    # 勇者N は N+1 でなるだけ殺す
    kill_n_plus_1 = min(B[-1], A[-1])
    remain_B[-1] -= kill_n_plus_1

    # 勇者i は i でなるだけ殺す
    kill_i = np.min((remain_B, remain_A), axis=0)
    remain_A -= kill_i
    remain_B -= kill_i

    # 勇者i は i+1 でなるだけ殺す
    kill_i_plus_1 = np.min((remain_B[:-1], remain_A[1:]), axis=0)
    kill_count = kill_n_plus_1 + np.sum(kill_i) + np.sum(kill_i_plus_1)
    return int(kill_count)


def load_input_as_int_array() -> np.ndarray:
    return np.array([int(v) for v in input().split(" ")])


def main() -> None:
    N = load_input_as_int_array()
    A = load_input_as_int_array()
    B = load_input_as_int_array()
    result = calc(N, A, B)
    print(result)


main()

Submission status: Wrong Answer

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

ans = 0
remain_a = 0
remain_b = 0
for (a, b) in zip(A[::-1], B[::-1]):
    if remain_b != 0:
        if a >= remain_b:
            ans += remain_b
            a -= remain_b
            remain_b = 0
        else:
            ans += a
            a = 0
            remain_b = 0
    if remain_a != 0:
        if remain_a >= b:
            ans += b
            remain_a = 0
            b = 0
        else:
            ans += remain_a
            remain_a = 0
            b -= remain_a

    if a >= b:
        ans += b
        remain_a = a - b
        remain_b = 0
    else:
        ans += a
        remain_a = 0
        remain_b = b - a

remain_a += A[0]
if remain_a >= remain_b:
    ans += remain_b
else:
    ans += remain_a
print(ans)

Submission status: Wrong Answer

Solution code:

# 2 5 1 7 3
# 4 2 2 5
#   2 
# 1 4 1 
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
b.append(0)
kuriage = 0
total = 0
for i in range(n+1):
        # print(str(i)+'ばんめ')
        # if a[i] <= b[i]:
        #         print('if'+str(1))
        #         kuriage = b[i] - a[i]
        #         # b[i] = b[i]+kuriage
        #         total += a[i]
        #         print(kuriage)
        #         print(total)
        if kuriage+b[i] >= a[i]:
                # print('if1')
                res = a[i] - kuriage
                kuriage = b[i] - res
                # b[i] = b[i]+kuriage
                total += a[i]
                # print(kuriage)
        elif kuriage+b[i] < a[i]:
                # print('if2')
                # total += a[i] - (kuriage+b[i])
                total += kuriage+b[i]
                kuriage = 0
                # print(kuriage)
print(total)

Submission status: Wrong Answer

Solution code:
n = int(input())
n
a = list(map(int, input().split(' ')))#モンスター
b = list(map(int, input().split(' ')))#勇者
b.append(0)
beat = 0

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

print(beat)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(int(x) for x in input().split())
B = list(int(x) for x in input().split())
a = 0
b = 0
for x in range(N):
    B[x] = B[x] + a
    if A[x] > B[x]:
        b = b + B[x]
        a = 0
    else:
        b = b + A[x]
        if A[x] > a:
            a = B[x] - A[x]
        else:
            a = B[x]
if A[N - 1] > B[N - 1]:
    print(b)
else:
    if A[N] > a:
        print(b + a)
    else:
        print(b + A[N])

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
ans=0
flg=0
Ttmp=0
for i in range(N):
    if flg == 1:
        Atmp=Ttmp
    else:
        Atmp=A[i]
    flg=0
    Btmp=B[i]

    if Atmp <= Btmp:
        ans+=A[i]
        Btmp-=A[i]
    else:
        ans+=B[i]
        continue
        
    if A[i+1] <= Btmp:
        ans+=A[i+1]
    else:
        ans+=Btmp
        Ttmp=A[i+1]-Btmp
        flg=1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
n
a = list(map(int, input().split(' ')))#モンスター
b = list(map(int, input().split(' ')))#勇者
b.append(0)
beat = 0

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

print(beat)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a_list = list(map(int,input().split()))
b_list = list(map(int,input().split()))
count = 0
for i in range(n):
  if a_list[i]+a_list[i+1] <= b_list[i]:
    count += a_list[i]+a_list[i+1]
  else:
    count += b_list[i]
if count > sum(a_list):
  print(sum(a_list))
else:
  print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().strip().split()))
b = list(map(int, input().strip().split()))
b.append(0)
kill_count = 0
for i in range(n+1):
    ta = a[i]
    tb = b[i]

    if b[i] >= a[i]:
        kill_count += a[i]
        b[i] -= a[i]
        if i < n:
            b[i+1] += b[i]
    else:
        kill_count += tb

print(kill_count)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
reverse_A = list(reversed(A))
reverse_B = list(reversed(B))
sum = 0

if (B[N-1]-A[N]) >= (B[0]-A[0]):
  for n in range(len(reverse_A)):
    if n == 0:
      if (reverse_B[n]- reverse_A[n]) >= 0:
        sum += reverse_A[n]
        temp = reverse_B[n] - reverse_A[n]
      else:
        sum += reverse_B[n]
        temp = 0
    elif n >= 1 and n <= (N-1):
      if (temp + reverse_B[n]- reverse_A[n]) >= 0:
        sum += reverse_A[n]
        if (temp - reverse_A[n]) >= 0:
          temp = reverse_B[n]
        else:
          temp = temp + reverse_B[n]- reverse_A[n]
      else:
        sum += reverse_B[n]
        temp = 0
    else:
      if (temp - reverse_A[n]) >= 0:
        sum += reverse_A[n]
      else:
        sum += temp
else:
  for n in range(len(A)):
    if n == 0:
      if (B[n]- A[n]) >= 0:
        sum += A[n]
        temp = B[n] - A[n]
      else:
        sum += B[n]
        temp = 0
    elif n >= 1 and n <= (N-1):
      if (temp + B[n]- A[n]) >= 0:
        sum += A[n]
        if (temp - A[n]) >= 0:
          temp = B[n]
        else:
          temp = temp + B[n] - A[n]
      else:
        sum += B[n]
        temp = 0
    else:
      if (temp - A[n]) >= 0:
        sum += A[n]
      else:
        sum += temp
print(sum)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

ans = sum(A)

yojo = 0
ne = B[0]

for i in range(N):
    yojo = A[i] - ne
    if yojo == 0:
        if i != N-1:
            ne = B[i+1]

    elif yojo < 0:
        if i != N-1:
            ne = B[i+1] + abs(yojo)
    else:
        ans -= yojo
        if i != N-1:
            ne = B[i+1]

ne = ne - A[-2]
if A[-1] - ne > 0:
    ans -= abs(A[-1]-ne)

print(ans)

Submission status: Wrong Answer

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

i = N
if A[i] >= B[i-1]:
    A[i] -= B[i-1]
    B[i-1] = 0
else:
    B[i-1] -= A[i]
    A[i] = 0
#print(A,B)
sum_A -= sum(A)
print(sum_A)

Submission status: Wrong Answer

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

monster = 0
addPower = 0

for i in range(N):
    #print(A[i],'+', A[i+1], ' vs ', B[i], end = ' => ')
    AA = A[i] + A[i+1]
    BA = B[i] - A[i]
    BAA= B[i] - AA
    if BAA >= 0:
        monster += AA
        A[i+1] -= min(A[i+1], BA)
    else:
        monster += B[i]

print(monster)

Submission status: Wrong Answer

Solution code:
N = int(input())
Alist = [int(i) for i in list(input().split())]
Blist = [int(i) for i in list(input().split())]
ans = 0
for i in range(N):
    tmp = Alist[i]-Blist[i]
    if tmp < 0:
        ans += Alist[i]
        Blist[i] = -1 * (Alist[i]-Blist[i])
    else:
        ans += Blist[i]
        continue
    tmp = Alist[i+1] - Blist[i]
    if tmp < 0:
        ans += Alist[i+1]
    else:
        ans += Blist[i]
        Alist[i+1] = tmp

print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
a = int(input())
mon = list(map(int, input().split(" ")))
att = list(map(int, input().split(" ")))
kil = 0

b = len(mon)

for i in range(b):
#    print(mon[i])
    if i == a :
        if  mon[i] >= att[i-1]:
            kil = kil + att[i-1]
        elif mon[i] < att[i-1] :
            kil = kil + mon[i]
    elif i > 0 and att[i-1] > 0 :
        if mon[i] >= att[i-1]:
            kil = kil + att[i-1]
            mon[i] = mon[i] - att[i-1] 
        elif mon[i] < att[i-1] :
            kil = kil + mon[i]
            continue
    elif mon[i] >= att[i]:
        kil = kil + att[i]
        att[i] = 0
    elif mon[i] < att[i] :
        kil = kil + mon[i]
        att[i] = att[i] - mon[i]
#    print('result'+str(i)+':')
#    print('kil:'+str(kil))
#    print('zanAtt:'+att[])
        
print(kil)

Submission status: Wrong Answer

Solution code:
n = int(input())
a_list = list(map(int,input().split()))
b_list = list(map(int,input().split()))
count = 0
for i in range(n):
  if a_list[i]+a_list[i+1] <= b_list[i]:
    count += a_list[i]+a_list[i+1]
  else:
    count += b_list[i]
print(count)

Submission status: Wrong Answer

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

ans = 0
remain_a = 0
remain_b = 0
for (a, b) in zip(A[::-1], B[::-1]):
    if remain_b != 0:
        if a >= remain_b:
            ans += remain_b
            a -= remain_b
            remain_b = 0
        else:
            ans += a
            a = 0
            remain_b = 0
    a += remain_a

    if a >= b:
        ans += b
        remain_a = a - b
        remain_b = 0
    else:
        ans += a
        remain_a = 0
        remain_b = b - a

remain_a += A[0]
if remain_a >= remain_b:
    ans += remain_b
else:
    ans += remain_a
print(ans)

Submission status: Wrong Answer

Solution code:
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 += A[i]
        B[i] = B[i] - A[i]
    elif A[i] >= B[i]:
        total += B[i]
        A[i] = A[i] - B[i]
        B[i] = 0
        continue

    if A[i+1] >= B[i]:
        total += B[i]
        A[i+1] = A[i+1] - B[i]
    elif A[i+1] < B[i]:
        total += A[i+1]
        A[i+1] = B[i] - A[i+1]

print(total)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
ans=0
flg=0
Ttmp=0
for i in range(N):
    if flg == 1:
        Atmp=Ttmp
    else:
        Atmp=A[i]
    flg=0
    Btmp=B[i]

    if Atmp <= Btmp:
        ans+=A[i]
        Btmp-=A[i]
    else:
        ans+=B[i]
        continue
    flg=1    
    if A[i+1] <= Btmp:
        ans+=A[i+1]
    else:
        ans+=Btmp
        Ttmp=A[i+1]-Btmp
        
print(ans)

Submission status: Wrong Answer

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

result = 0
for i in range(N):
    sum = int(A[1][i]) + int(A[1][i+1])
    result += min(sum, int(B[1][i]))

print(result)

Submission status: Wrong Answer

Solution code:
N = int(input())
N = N+1
monsters = list(map(int, input().split()))
heros = list(map(int, input().split()))
stack = 0
count = 0
point = 0
for i in range(0, len(heros)):
    point = monsters[i] - (stack + heros[i])
    if point < 0:
        stack = abs(point)
        count += monsters[i]
    else:
        count += heros[i]
count += stack
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
time = [list(map(int,input().split())) for i in range(2)]
monster=time[0]
power=time[1]
counter=0
for i in range(len(power)):
  cl1,cl2=monster[i],monster[i+1]
  if power[i]<max(cl1,cl2):
    counter=counter+power[i]
  else:
    maximum=max(cl1,cl2)
    counter=counter+maximum
    capacity=power[i]-maximum
    if capacity<min(cl1,cl2):
      counter=counter+capacity
    else:
      counter=counter+min(cl1,cl2)
print(counter)

Submission status: Wrong Answer

Solution code:
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] -= monsters[i]
    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)

Submission status: Wrong Answer

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

print(sum)

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):
    tmp=min(a[i],b[i])
    b[i]-=tmp
    ans+=tmp
    tmp=min(a[i+1],b[i])
    ans+=tmp
print(ans)

Submission status: Wrong Answer

Solution code:

# 2 5 1 7 3
# 4 2 2 5
#   2 
# 1 4 1 
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
b.append(0)
kuriage = 0
total = 0
for i in range(n+1):
        # print(str(i)+'ばんめ')
        # if a[i] <= b[i]:
        #         print('if'+str(1))
        #         kuriage = b[i] - a[i]
        #         # b[i] = b[i]+kuriage
        #         total += a[i]
        #         print(kuriage)
        #         print(total)
        if kuriage+b[i] > a[i]:
                # print('if1')
                kuriage = kuriage+b[i] - a[i]
                # b[i] = b[i]+kuriage
                total += a[i]
                # print(kuriage)
        else:
                # print('if2')
                # total += a[i] - (kuriage+b[i])
                total += kuriage+b[i]
                kuriage = 0
                # print(kuriage)
print(total)

Submission status: Wrong Answer

Solution code:
from sys import stdin


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

    print(sum(Bs))

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

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

    # for i in range(1, N):
    #     a = As[i]
    #     b = Bs[i - 1]
    #     if a == 0 or b == 0:
    #         pass
    #     elif b < a:
    #         result += b
    #         Bs[i - 1] = 0
    #     else:
    #         result += a
    #         Bs[i - 1] -= a
    #     a = As[i]
    #     b = Bs[i]
    #     if a == 0 or b == 0:
    #         pass
    #     elif b < a:
    #         result += b
    #         Bs[i] = 0
    #     else:
    #         result += a
    #         Bs[i] -= a

    # print(result)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
from sys import stdin
a = [int(x) for x in stdin.readline().rstrip().split()]
b = [int(x) for x in stdin.readline().rstrip().split()]

su = sum(a)
a_len = len(a)
count = 0
i = 0
a_idx = 0
b_idx = 0
a_num = a[a_idx]
b_num = b[b_idx]
while(b_idx < n and a_idx <= a_len and count < su):
    
    a_num = a_num - 1
    
    if i == b_num:
        b_num = b[b_idx]
        b_idx += 1
        i = 0
    elif a_num == 0:
        a_num = a[a_idx]
        a_idx += 1
    count += 1
    i += 1
    


print(count)

Submission status: Wrong Answer

Solution code:
from sys import stdin


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

    print(sum(As))

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

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

    # for i in range(1, N):
    #     a = As[i]
    #     b = Bs[i - 1]
    #     if a == 0 or b == 0:
    #         pass
    #     elif b < a:
    #         result += b
    #         Bs[i - 1] = 0
    #     else:
    #         result += a
    #         Bs[i - 1] -= a
    #     a = As[i]
    #     b = Bs[i]
    #     if a == 0 or b == 0:
    #         pass
    #     elif b < a:
    #         result += b
    #         Bs[i] = 0
    #     else:
    #         result += a
    #         Bs[i] -= a

    # print(result)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())
from sys import stdin
a = [int(x) for x in stdin.readline().rstrip().split()]
b = [int(x) for x in stdin.readline().rstrip().split()]

su = sum(a)
a_len = len(a)
count = 0
i = 0
a_idx = 0
b_idx = 0
a_num = a[a_idx]
b_num = b[b_idx]
while(b_idx < n and a_idx <= a_len and count < su):
    
    a_num = a_num - 1
    
    if i == b_num:
        b_num = b[b_idx]
        b_idx += 1
        i = 0
    elif a_num == 0:
        a_num = a[a_idx]
        a_idx += 1
    count += 1
    i += 1
    


print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

a_mid = sum(a[1:n])
if n > 2:
  b_mid = sum(b[1:n-1])
else:
  b_mid = 0

mid_nokori = a_mid - b_mid

if mid_nokori  > 0 :
  nokori0 = b[0] - a[0]
  nokorin = b[n-1] - a[n]
  if nokori0 <= 0 and nokorin <= 0:
    print(b_mid + b[0] + b[n-1])
  elif nokori0 <= 0 and nokorin > 0:
    print(b_mid + b[0] + a[n] + 
          min(mid_nokori,nokorin))
  elif nokori0 > 0 and nokorin <= 0:
    print(b_mid + a[0] + b[n-1] +
         min(mid_nokori,nokori0))
  elif nokori0 > 0 and nokorin > 0:
    print(b_mid + a[0] + a[n] +
         min(mid_nokori,nokori0 + nokorin))
    
else:
  print(a_mid + min(a[0],b[0]) + min(a[n],b[n-1]))

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
A.insert(0, 0) #モンスター
B.insert(0, 0) #勇者の能力
C=[0]*(N+1)     #次の街に回せる能力
D=[0]*(N+1) #必要な担当勇者(iが等しい)の能力
E=[0]*(N+2) #その街で実際に倒す数
F=[0]*(N+2) #合計能力

for i in range(1,N+1):
  if i==1:
    F[i]=B[i]
  else:
    F[i]=B[i]+C[i-1] #余った能力をもらったうえで使える能力を計算
    
  if F[i]>=A[i]: #所有能力が勝ってたら
    E[i]=A[i]
    C[i]=F[i]-A[i]
  else:
    E[i]=F[i]
    C[i]=0

  #print(i,A[i],B[i],C[i],D[i],E[i],F[i])

if C[N]>=A[N+1]: #剰余能力がモンスターより多かったら
  E[N+1]=A[N+1]
else:
  E[N+1]=C[N]

ans=sum(E)
#print(E)
print(ans)

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

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

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):
    p=min(A[i]+A[i+1],B[i])
    ans=ans+p
    if A[i]+A[i+1]<=B[i]:
        A[i+1]=max(0,A[i+1]-B[i]+A[i])
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input()) + 1

A = input().split()

B = input().split()

enemy = np.zeros(N)
saver = np.zeros(N)

beated = 0
over = 0

for i in range(N - 1):
    enemy[i] = int(A[N - i - 2])
    saver[i] = int(B[N - i - 2])

enemy[N - 1] = int(A[N - 1])

for i in range(N):
    if(enemy[i] - over > saver[i]):
        beated = beated + saver[i] + over
        over = 0
    else:
        beated = beated + enemy[i]
        over = saver[i] + over - enemy[i]
         
print(int(beated))

Submission status: Wrong Answer

Solution code:
heroes = int(input())
puts = input()
monsters = puts.split()
puts = input()
strength = puts.split()
Ans = 0

for i in range(heroes):
	if (int(strength[i]) > int(monsters[i])):
		if(int(strength[i]) > int (monsters[i]) + int (monsters[i+1])):
			Ans += int(monsters[i]) + int(monsters[i+1])
		else:
			monsters[i+1] = int(monsters[i+1]) + int(monsters[i]) - int(strength[i])
			Ans += int(strength[i])
	else:
		Ans += int(strength[i])

print(Ans)

Submission status: Wrong Answer

Solution code:

# 2 5 1 7 3
# 4 2 2 5
#   2 
# 1 4 1 
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
b.append(0)
kuriage = 0
total = 0
for i in range(n+1):
        # print(str(i)+'ばんめ')
        # if a[i] <= b[i]:
        #         print('if'+str(1))
        #         kuriage = b[i] - a[i]
        #         # b[i] = b[i]+kuriage
        #         total += a[i]
        #         print(kuriage)
        #         print(total)
        if kuriage+b[i] >= a[i]:
                # print('if1')
                kuriage = kuriage+b[i] - a[i]
                # b[i] = b[i]+kuriage
                total += a[i]
                # print(kuriage)
        else:
                # print('if2')
                # total += a[i] - (kuriage+b[i])
                total += kuriage+b[i]
                kuriage = 0
                # print(kuriage)
print(total)

Submission status: Wrong Answer

Solution code:
"""
# 標準入力取得
## 文字列
 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())

## 数値
 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]
"""

import math
import sys
import itertools
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

if __name__ == "__main__":
    n= int(sys.stdin.readline())
    a= list(map(int, sys.stdin.readline().split()))
    b= list(map(int, sys.stdin.readline().split()))

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

Submission status: Wrong Answer

Solution code:
import logging

logging.basicConfig(level=logging.INFO, format="%(message)s")
#logging.disable(logging.CRITICAL)

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

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

    if B[N - 1] > A[N]:
        counter += A[N]
    elif B[N - 1] != 0:
        counter += B[N - 1]

    print(counter)
            
    
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()))
a = a[::-1]
b = b[::-1]

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