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

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

        if a[i] < b[i]:
            b[i] -= a[i]
            a[i] = 0
        else:
            a[i] -= b[i]
print(s1 - sum(a))

Submission status: Wrong Answer

Solution code:

n=int(input())
a_L=list(map(int,input().split()))
b_L=list(map(int,input().split()))
ans=0
amp=0
at=0
print(a_L)
for i in range(n):
    at=min(a_L[i]+a_L[i+1],b_L[i])
    if at>a_L[i]:
        tmp=at-a_L[i]
    else:
        tmp=0
    ans+=at
    a_L[i+1]=a_L[i+1]-tmp
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(beated)

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()]
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:
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
ans=0

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

print(ans)

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
    elif n == N:
      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
    elif n == N:
      if (temp - A[n]) >= 0:
        sum += A[n]
      else:
        sum += temp
print(sum)

Submission status: Wrong Answer

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

taos = 0
keep = 0

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

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

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

total = []
for i in range(len(B)):
    j = i + 1
    Ai = A[i]; Aj = A[j]
    Bi = B[i]

    m = Ai + Aj
    t = Bi

    if m > t:
        total.append(Bi)
    else:
        total.append(Ai + Aj)

print(sum(total))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

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

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

        if i == n - 1:
            if tmp <= a[i + 1]:
                ans += tmp
            else:
                ans += a[i + 1]
    print(ans)


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

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)

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

Submission status: Wrong Answer

Solution code:
n = int(input())
list_a = []
list_b = []
list_a = input().split()
list_b = input().split()

x = 0
a = int(list_a[n])
for i in range(n):
    ii = n - i -1
    if a + int(list_a[ii]) < int(list_b[ii]):
        x += a + int(list_a[ii])
        a = 0
    else:
        a = a + int(list_a[ii]) - int(list_b[ii])
        x += int(list_b[ii])

print(x)

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

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy,copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
    n=INT()
    a=LIST()
    b=LIST()

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

    ki+=min(a[-1], tmp)
    print(ki)

if  __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
a = input().split()
b = input().split()
alist = []
blist = []
alist.extend(a)
blist.extend(b)
for i in range(n+1):
  alist[i] = int(alist[i])
for j in range(n):
  blist[j] = int(blist[j])

taoshita = []
for k in range(n):
  monster = alist[k]+alist[k+1]
  if blist[k] < monster:
    taoshita.append(blist[k])
  else:
    taoshita.append(monster)
print(sum(taoshita))

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]
    else:
        counter += B[N - 1]

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

Submission status: Wrong Answer

Solution code:
from sys import stdin
from itertools import zip_longest

readline = stdin.readline


def nl():
    """
    空白区切り行入力を`int iter`に変換
    """
    return map(int, readline().split())


def ns():
    """
    入力を`[\\s]`を除いて文字列として取得
    """
    return readline().rstrip()


def ni():
    """
    入力を`int`に変換
    """
    return int(ns())


def nf():
    """
    入力全て(EOFまで)を`int iter`に変換
    """
    return map(int, open(0).read().split())


def main():
    _ = ni()
    al = nl()
    bl = nl()
    p = 0
    count = 0
    for a, b in zip_longest(al, bl):
        ta = max(a - p, 0)
        if ta == 0:
            count += a
            p = b
            continue

        if b:
            p = max(b - ta, 0)
        else:
            p = 0
            b = 0
        count += b if p == 0 else a

    print(count)


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

count = 0

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

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

print(count)

Submission status: Wrong Answer

Solution code:
# ABC 135, C
from itertools import permutations

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

total = 0
for i in range(n):
    if B[i] >= A[i]+A[i+1]:
        total += A[i]+A[i+1]
        A[i] = 0
        A[i+1] = 0
        B[i] = 0
print(sum(B) + total)

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]
    C[i+1] = -a
if C[N] > 0:
  if A[N] < C[N]:
    count += A[N]
  else:
    count += C[N]
print(count)

Submission status: Wrong Answer

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

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]
    else:
        b = b + A[x]
        a = B[x] - A[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()))
A=[0]*n
for i in range(n):
    A[i]=a[i]+a[i+1]
x=0
loop=0
while(1):
    loop+=1
    flag=0
    for i in range(n):
        if A[i]<=b[i] and A[i]>0:
            flag=1
            x+=A[i]
            b[i]-=A[i]
            A[i]=0
            if i<n-1:
                A[i+1]-=a[i+1]
            if i>0:
                A[i-1]-=a[i]
            a[i+1]=0
            a[i]=0
    if flag==0:
        break

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

print(x)

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

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()]
print('OK')
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:
N = int(input())
monster_list = list(map(int, input().split()))
brave_list = list(map(int, input().split()))

iter = int(len(monster_list) / 2)
counter = 0
for i in range(iter):
    # 左
    ## 左側
    if i != 0:
        defate = min(monster_list[i], brave_list[i - 1])
        counter += defate
        monster_list[i] -= defate
        brave_list[i - 1] -= defate if defate < brave_list[i - 1] else 0
    ## 右側
    defate = min(monster_list[i], brave_list[i])
    counter += defate
    monster_list[i] -= defate
    brave_list[i] -= defate if defate < brave_list[i] else 0

    # 右
    ## 左側
    right = len(monster_list) - 1 - i
    defate = min(monster_list[right], brave_list[right - 1])
    counter += defate
    monster_list[right] -= defate
    brave_list[right - 1] -= defate if defate < brave_list[right - 1] else 0
    ## 右側
    if i != 0:
        defate = min(monster_list[right], brave_list[right])
        counter += defate
        monster_list[right] -= defate
        brave_list[right] -= defate if defate < brave_list[right] else 0
    
if not (len(monster_list) / 2).is_integer():
    # 真ん中の街の処理 
    # index = iter
    # 左側
    defate = min(monster_list[iter], brave_list[iter - 1])
    counter += defate
    monster_list[iter] -= defate
    brave_list[iter - 1] -= defate if defate < brave_list[iter - 1] else 0
    # 右側
    defate = min(monster_list[iter], brave_list[iter])
    counter += defate
    monster_list[iter] -= defate
    brave_list[iter] -= defate if defate < brave_list[iter - 1] else 0

print(counter)

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

killed = 0
reserved_power = 0

for i in range(N):

    if i == 0:
        battle = B[i] - A[i]
        if battle >= 0:
            reserved_power = battle
            killed += A[i]
        else:
            reserved_power = 0
            killed += B[i]

    elif i == N - 1:
        other_monster = A[i] - reserved_power
        if other_monster <= 0:
            reserved_power = B[i]
            alive = 0
            killed += A[i]
            killed += min(reserved_power, A[i+1])
        else:
            killed += reserved_power
            battle = B[i] - other_monster - A[i+1]
            if battle >= 0:
                killed += other_monster + A[i+1]
            else:
                killed += B[i]

    else:
        other_monster = A[i] - reserved_power

        if other_monster <= 0:
            reserved_power = B[i]
            alive = 0
            killed += A[i]
        else:
            battle = B[i] - other_monster

            if battle >= 0:
                reserved_power = battle
                killed += other_monster
            else:
                reserved_power = 0
                killed += B[i]


print(killed)

Submission status: Wrong Answer

Solution code:
n = int(input())
monster = list(map(int, input().split()))
yuusya = list(map(int, input().split()))
sub = 0
for i in range(n,0,-1):
  #print("yuusya[i-1]",yuusya[i-1],"monster[i]",monster[i])
  if yuusya[i-1] > monster[i]:
    sub += monster[i]
    yuusya[i-1] -= monster[i]
    monster[i] = 0
  else:
    sub += yuusya[i-1]
    monster[i] -= yuusya[i-1]
    yuusya[i-1] = 0
  if yuusya[i-1] > monster[i-1]:
    sub += monster[i-1]
    yuusya[i-1] -= monster[i-1]
    monster[i-1] = 0
  else:
    sub += yuusya[i-1]
    yuusya[i-1] = 0
if yuusya[0] > monster[0]:
  sub+=monster[0]
else:
  sub+=yuusya[0]
print(sub)

Submission status: Wrong Answer

Solution code:
N = int(input())
mnstr = list(map(int, input().split()))
yusha = list(map(int, input().split()))
sum = 0
killed = 0

for i in range(N):
  killedtemp = min(mnstr[i], yusha[i])#iの勇者が倒したモンスターiの数
  yusha[i] = max(0, yusha[i]-mnstr[i])
  killedtemp += min(mnstr[i+1], yusha[i])#iの勇者が倒したモンスターi+1の数
  mnstr[i+1] = mnstr[i] + mnstr[i+1] - killedtemp
  killed += killedtemp
  
print(killed)

Submission status: Wrong Answer

Solution code:
n = int(input())
list_a = []
list_b = []
list_a = input().split()
list_b = input().split()

x = 0
a = int(list_a[n])
for i in range(n):
    ii = n - i -1
    if a + int(list_a[ii]) <= int(list_b[ii]):
        x += a + int(list_a[ii])
        a = 0
    else:
        a = a + int(list_a[ii]) - int(list_b[ii])
        x += int(list_b[ii])

print(x)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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


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

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:
            break
        ne = B[i+1]
        ne += yojo
    else:
        if i != N-1:
            ne = B[i+1]
        ans -= abs(yojo)
    

print(ans)

Submission status: Wrong Answer

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

attack = 0

for i in range(N):
  if i != (N-1):
    if a[i] > b[i]:
      attack += b[i]
      a[i] = a[i]-b[i]
      b[i] = 0
    else:
      attack += a[i]
      a[i] = 0
      b[i] = b[i]-a[i]
      if (b[i]-a[i]) > 0:
        attack += min(a[i+1], b[i])
        a[i+1] = max(a[i+1]-b[i], 0)
        b[i] = 0
  else:
    if a[N-1] > b[N-1]:
      attack += b[i]
      a[N-1] = a[N-1]-b[N-1]
      b[N-1] = 0
    else:
      attack += a[N-1]
      a[N-1] = 0
      b[N-1] = b[N-1]-a[N-1]
      if (b[N-1]-a[N-1]) > 0:
        attack += min(a[N], b[N-1])
        a[N] = max(a[N]-b[N-1], 0)
        b[N-1] = 0

print(attack)

Submission status: Wrong Answer

Solution code:
N=int(input())
# L=[]
# for i in range(N):
#     L.append(int(read_input()))

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

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

Submission status: Wrong Answer

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

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

taos = 0
nokori = 0
keep = 0

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

Submission status: Wrong Answer

Solution code:
import numpy as np

s = input().split()
N=int(s[0])
s = input().split()
a=[int(n) for n in s]
s = input().split()
b = [int(n) for n in s]
c=0
for i in range(N):
    if a[i]+a[i+1] < b[i]:
        if a[i+1]+a[i]-b[i] < 0:
            c = c +a[i+1]+a[i]
            a[i+1]=0
        else:
            a[i+1] = a[i+1]+a[i]-b[i]

        
    elif a[i]+a[i+1] == b[i]:
        c=c+b[i]
        a[i+1]=0
    else:
        c = c+b[i]
        if a[i+1]>a[i]:
            a[i+1]=a[i+1]+a[i]-b[i]
print(c)

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

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

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

print(max_lose_ene)

Submission status: Wrong Answer

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

ans=0
bt=0
B.append(0)
for i in range(N+1):
    at=max(0,A[i]-bt)
    if at > B[i]:
        ans+=at-B[i]
    else:
        bt=max(0,B[i]-at)

print(sum(A)-ans)

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]
Sum = 0
for k in range(N):
    if b[k] > a[k+1]:
        Sum += a[k+1]
        b[k] = b[k] - a[k+1]
    else:
        Sum += b[k]
        b[k] = 0
    if b[k] - a[k] > 0:
        Sum += a[k]
        a[k] = 0
    else:
        Sum += b[k]
        a[k] = a[k] - b[k]
print(Sum)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque
import sys
import heapq
import bisect
import math
import itertools
import string
import queue
import copy
import time
import numpy as np
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

n=inp()
a = inpl()
b_ori = inpl()
b_ori.sort(reverse=True)
a_index = (np.array(a)).argsort()
a_index=a_index.tolist()
a_index.remove(n)
b = [0] * n
ans=0
for i in range(n):
    b[a_index[i]]=b_ori[i]
for i in range(n):
    tmp=a[i] - b[i]
    if tmp >= 0:
        ans += b[i]
    else:
        ans += a[i]
        tmp=-tmp
        temp = a[i + 1] - tmp
        if temp >= 0:
            ans += tmp
            a[i + 1] -= tmp
        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()))
C = 0
if A[0] > B[0]:
    C += B[0]
    B[0] = 0
else:
    B[0] = (B[0] - A[0])
    C += A[0]
for i in range(1,N):
    if A[i] > (B[i-1]+B[i]):
         C += (B[i-1]+B[i])
         B[i] = 0
    else:
        B[i] = B[i]-(A[i]-B[i-1])
        C += A[i]
if A[N] > B[N-1]:
    C += B[N-1]
else:
    C += A[N]
print(C)

Submission status: Wrong Answer

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

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

print(sum_hunt)

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] = 0
    else:
      attack_l[1] = monsters[i] - attack_l[0]
      attack_l[0] = 0
  elif (monsters[i] - attack) > 0:
    killed += attack
    attack_l[0] = 0
    attack_l[1] = 0
  elif (monsters[i] - attack) == 0:
    killed += monsters[i]
    attack_l[0] = 0
    attack_l[1] = 0

print(killed)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

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

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


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()))
B.append(0)

diff, old_diff, B_sum = [0, 0, 0]
for i in range(N+1):
  diff = B[i] - A[i] + old_diff
  if diff < 0:
    diff = 0
    B_sum = B_sum + B[i] + old_diff
  else:
    B_sum = B_sum + A[i]
  old_diff = diff
    
print(B_sum)

Submission status: Wrong Answer

Solution code:
n = int(input())
list_a = input().split()
list_b = input().split()

x = 0
hp = 0

for i in range(n):
    a = int(list_a[i])
    b = int(list_b[i])
    a_after = a - hp
    if b >= a_after:
        b -= a_after
        x += a
        hp = b
    else:
        x += (b + hp)
        hp = 0
        
if hp >= int(list_a[n]):
    x += int(list_a[n])
else:
    x += hp

print(x)

Submission status: Wrong Answer

Solution code:

n=int(input())
a_L=list(map(int,input().split()))
b_L=list(map(int,input().split()))
ans=0
amp=0
at=0
for i in range(n):
    at=min(a_L[i]+a_L[i+1],b_L[i])
    tmp=at
    ans+=at
    a_L[i+1]=a_L[i+1]-tmp+a_L[i]
print(ans)

Submission status: Wrong Answer

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

sum = 0
rest_hero = 0

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

print(sum)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

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

print(ans)