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

ans = 0
for i in range(N):
    hero = lst_B[i]
    if lst_A[i] <= hero:
        ans += lst_A[i]
        hero -= lst_A[i]
        lst_A[i] = 0
    else:
        ans += hero
        lst_A[i] -= hero
        hero = 0
    if lst_A[i+1] <= hero:
        ans += lst_A[i+1]
        hero -= lst_A[i+1]
        lst_A[i] = 0
    else:
        ans += hero
        lst_A[i+1] -= hero
        hero = 0
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

brave_num = int(input())
monster_list = [int(i) for i in input().split(" ")]
brave_list = [int(i) for i in input().split(" ")]
ans = 0
for i in range(brave_num):
    if monster_list[i] < brave_list[i]:
        ans += monster_list[i]
        brave_list[i] -= monster_list[i]
        monster_list[i] = 0
        if monster_list[i + 1] < brave_list[i]:
            ans += monster_list[i + 1]
            monster_list[i + 1] -= 0
        else:
            ans += brave_list[i]
            monster_list[i + 1] -= brave_list[i]
    else:
        monster_list[i] -= brave_list[i]
        ans += brave_list[i]
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

maxCount = 0
for i in range(0, n):
    # i番目の敵をできるだけ倒す
    if a[i] > b[i]:
        maxCount += b[i]
        break
    else:
        maxCount += a[i]
        b[i] -= a[i]
    # i+1番目の敵をできるだけ倒す
    if a[i+1] > b[i]:
        maxCount += b[i]
        a[i+1] -= b[i]
    else:
        maxCount += a[i+1]
        a[i+1] = 0

print(maxCount)

Submission status: Wrong Answer

Solution code:
a = int(input())
ar = list(map(int,input().split(" ")))
br = list(map(int,input().split(" ")))
count = 0
for i in range(a):
    if ar[i] <= br[i]:
        count += ar[i]
        ar[i] == 0
        br[i] -= ar[i]
        if ar[i+1] <= br[i]:
            count += ar[i+1]
            ar[i] = 0
        else:
            ar[i+1] -= br[i]
            count += br[i]
    else:
        ar[i] -= br[i]
        count += br[i]
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

maxCount = 0
for i in range(0, n):
    # i番目の敵をできるだけ倒す
    if a[i] > b[i]:
        maxCount += b[i]
        b[i] = 0
    else:
        maxCount += a[i]
        b[i] -= a[i]
    # i+1番目の敵をできるだけ倒す
    if a[i + 1] > b[i]:
        maxCount += b[i]
    else:
        maxCount += a[i + 1]

print(maxCount)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

maxCount = 0
for i in range(0, n):
    # i番目の敵をできるだけ倒す
    if a[i] > b[i]:
        maxCount += b[i]
        b[i] = 0
    else:
        maxCount += a[i]
        b[i] -= a[i]
    # i+1番目の敵をできるだけ倒す
    if a[i + 1] > b[i]:
        maxCount += b[i]
    else:
        maxCount += a[i + 1]

    print(maxCount)

Submission status: Wrong Answer

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

B.append(0)
cnt = 0
for i in range(N+1):
    if B[i]<A[i]:
        cnt += B[i]
    else:
        cnt += A[i]
        B[i] -= A[i]
        if i!=N:
            B[i+1] += B[i]
print(cnt)

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

Submission status: Wrong Answer

Solution code:
def getInt(): return int(input())

def getIntList(): return [int(x) for x in input().split()]

N = getInt()
A = getIntList()
B = getIntList()
sum = 0
sum += min(A[0],B[0])
f = min(A[1],B[0]-min(A[0],B[0]))
sum += f
print(sum)
for i in range(N-1):
    sum += min(A[i+1]-f,B[i+1])
    f = min(A[i+2],B[i+1]-min(A[i+1]-f,B[i+1]))
    sum += f
print(sum)

Submission status: Wrong Answer

Solution code:
def getInt(): return int(input())

def getIntList(): return [int(x) for x in input().split()]

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

Submission status: Wrong Answer

Solution code:
N = [int(i) for i in input().split()][0]
A = [float(i) for i in input().split()]
B = [float(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(int(cnt))

Submission status: Wrong Answer

Solution code:
def getInt(): return int(input())

def getIntList(): return [int(x) for x in input().split()]

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

Submission status: Wrong Answer

Solution code:
def getInt(): return int(input())
 
def getIntList(): return [int(x) for x in input().split()]
 
N = getInt()
A = getIntList()
B = getIntList()
sum = 0
sum += min(A[0],B[0])
sum += min(A[1],B[0]-min(A[0],B[0]))
for i in range(N-1):
    sum += min(A[i+1],B[i+1])
    sum += min(A[i+2],B[i+1]-min(A[i+1],B[i+1]))
print(sum)

Submission status: Wrong Answer

Solution code:
def getInt(): return int(input())

def getIntList(): return [int(x) for x in input().split()]

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

Submission status: Wrong Answer

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

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

#print (a)

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

Submission status: Wrong Answer

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

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

#print (a)

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

#print (a)

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

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()]
b_stock = 0
gekitai = 0
for i in range(n):

    if b_stock <= a[i]:
        gekitai += b_stock
        b_stock = 0
        a[i] -= b_stock

    else:
        gekitai += a[i]
        b_stock = 0
        a[i] = 0

    if b[i] <= a[i]:
        gekitai += b[i]

    else:
        gekitai += a[i]
        b_stock += b[i] - a[i]


if b_stock <= a[n]:
    gekitai += b_stock
else:
    gekitai += a[n]


print(gekitai)

Submission status: Wrong Answer

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

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

print(x)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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()]
S = 0

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

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

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

        if b[i]>=a[i+1]:
            ans += a[i+1]
        elif b[i]<a[i+1]:
            ans += b[i]
    elif b[i] < a[i]:
        ans += b[i]

print(ans)

Submission status: Wrong Answer

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


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

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

        right = min(a[i + 1], b[i])
        ans += right

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:

import sys
import math
INPUT = sys.stdin.readline
#入力関数
import sys
import math
INPUT = sys.stdin.readline
#入力関数
def SORO_INT(): return int(INPUT())
def MULT_INT_LIST(): return list(map(int, INPUT().split()))
def MULT_INT_MAP(): return map(int, INPUT().split())
def SORO_STRING(): return INPUT()
def MULT_STRING(): return INPUT().split()

def is_integer_num(n):
    if isinstance(n, int):
        return True
    if isinstance(n, float):
        return n.is_integer()
    return False
N = SORO_INT()
A = MULT_INT_LIST()
B = MULT_INT_LIST()
B.append(0)
count=0
t=0


t=0
if B[0]>A[0]:
    s = A[0]
    B[1]=B[1]+B[0]-A[0]
else:
    s = B[0]    


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

    if t>=0:
        #B[i+1]+=t
        count+=A[i]
    else:
        count+=B[i]
B[N] = t
q = B[N]-A[N]

if q<0:
    count+=B[N]
    print(count+s)
else:
    count+=A[N]
    print(count+s)

Submission status: Wrong Answer

Solution code:
import sys

N=input()
A=map(int, sys.stdin.readline().split())
B=map(int, sys.stdin.readline().split())

ans=0
mp=0

for i in range(N+1):
	a=A[i]
	if a<=mp:
		ans+=a
		mp-=a
		a-=a
	else:
		ans+=mp
		a-=mp
		mp-=mp


	if i<N:  mp+=B[i]
	if a<=mp:
		ans+=a
		mp-=a
		a-=a
	else:
		ans+=mp
		a-=mp
		mp-=mp

print ans

Submission status: Wrong Answer

Solution code:

import sys
import math
INPUT = sys.stdin.readline
#入力関数
import sys
import math
INPUT = sys.stdin.readline
#入力関数
def SORO_INT(): return int(INPUT())
def MULT_INT_LIST(): return list(map(int, INPUT().split()))
def MULT_INT_MAP(): return map(int, INPUT().split())
def SORO_STRING(): return INPUT()
def MULT_STRING(): return INPUT().split()

def is_integer_num(n):
    if isinstance(n, int):
        return True
    if isinstance(n, float):
        return n.is_integer()
    return False
N = SORO_INT()
A = MULT_INT_LIST()
B = MULT_INT_LIST()
B.append(0)
count=0
t=0
for i in range(1,N):
    if t>0:
        B[i]+=t
    t = B[i]-A[i]
    #print(t)

    if t>=0:
        #B[i+1]+=t
        count+=A[i]
    else:
        count+=B[i]
B[N] = t
q = B[N]-A[N]

if q<0:
    count+=B[N]
    print(count+B[0])
else:
    count+=A[N]
    print(count+B[0])

Submission status: Wrong Answer

Solution code:
import sys

N=input()
A=map(int, sys.stdin.readline().split())
B=map(int, sys.stdin.readline().split())

ans=0
mp=0

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

print ans

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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 = max(0, a[i] - tmp)

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

Submission status: Wrong Answer

Solution code:
N = int(input())
m = list(map(int, input().split()))
b = list(map(int, input().split()))
s = 0
for i in range(N):
  if m[i]<b[i]:
    s += b[i]
    m[i+1] += m[i]-b[i]
print(s)

Submission status: Wrong Answer

Solution code:

import sys
import math
INPUT = sys.stdin.readline
#入力関数
import sys
import math
INPUT = sys.stdin.readline
#入力関数
def SORO_INT(): return int(INPUT())
def MULT_INT_LIST(): return list(map(int, INPUT().split()))
def MULT_INT_MAP(): return map(int, INPUT().split())
def SORO_STRING(): return INPUT()
def MULT_STRING(): return INPUT().split()

def is_integer_num(n):
    if isinstance(n, int):
        return True
    if isinstance(n, float):
        return n.is_integer()
    return False
N = SORO_INT()
A = MULT_INT_LIST()
B = MULT_INT_LIST()
B.append(0)
count=0

for i in range(0,N):
    t = B[i]-A[i]
    #print(t)

    if t>=0:
        B[i+1]+=t
        count+=A[i]
    else:
        count+=B[i]

t = B[N]-A[N]


if t<0:
    count+=B[N]
    print(count)
else:
    count+=A[N]
    print(count)

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

Submission status: Wrong Answer

Solution code:
import sys

N=input()
A=map(int, sys.stdin.readline().split())
B=map(int, sys.stdin.readline().split())

ans=0
mp=0

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

print ans

Submission status: Wrong Answer

Solution code:
import sys

N=input()
A=map(int, sys.stdin.readline().split())
B=map(int, sys.stdin.readline().split())

ans=0
mp=0

for i in range(N+1):
	a=A[i]
	if i<N:  mp+=B[i]
	if a<=mp:
		ans+=a
		mp-=a
	elif mp<a:
		ans+=mp
		mp-=mp

print ans

Submission status: Wrong Answer

Solution code:

import sys
import math
INPUT = sys.stdin.readline
#入力関数
import sys
import math
INPUT = sys.stdin.readline
#入力関数
def SORO_INT(): return int(INPUT())
def MULT_INT_LIST(): return list(map(int, INPUT().split()))
def MULT_INT_MAP(): return map(int, INPUT().split())
def SORO_STRING(): return INPUT()
def MULT_STRING(): return INPUT().split()

def is_integer_num(n):
    if isinstance(n, int):
        return True
    if isinstance(n, float):
        return n.is_integer()
    return False
N = SORO_INT()
A = MULT_INT_LIST()
B = MULT_INT_LIST()
B.append(0)
count=0

for i in range(0,N):
    t = B[i]-A[i]
    #print(t)

    if t>=0:
        B[i+1]+=t
        count+=A[i]
    else:
        A[i+1]+=t
        count+=B[i]
t = B[N]-A[N]

if t<0:
    t = -t
    count+=t
    print(count)
else:
    count+=A[N]
    print(count)

Submission status: Wrong Answer

Solution code:

import sys
import math
INPUT = sys.stdin.readline
#入力関数
import sys
import math
INPUT = sys.stdin.readline
#入力関数
def SORO_INT(): return int(INPUT())
def MULT_INT_LIST(): return list(map(int, INPUT().split()))
def MULT_INT_MAP(): return map(int, INPUT().split())
def SORO_STRING(): return INPUT()
def MULT_STRING(): return INPUT().split()

def is_integer_num(n):
    if isinstance(n, int):
        return True
    if isinstance(n, float):
        return n.is_integer()
    return False
N = SORO_INT()
A = MULT_INT_LIST()
B = MULT_INT_LIST()
B.append(0)
count=0

for i in range(0,N):
    t = B[i]-A[i]
    #print(t)

    if t>=0:
        B[i+1]+=t
        count+=A[i]
    else:
        count+=B[i]
t = B[N]-A[N]

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


#担当する勇者が倒すモンスターの数
monster = 0
#前の勇者がi+1番目の町ですでに倒した数
defeat = 0
#倒したモンスターの合計
total = 0



for i in range(0, n):
    monster = a[i] + a[i+1] - defeat
    #print(monster)
    #print(defeat)
    #print(total)
    if a[i] >= b[i]:
        total += b[i]
        defeat = 0
    elif a[i] < b[i]:
        total += a[i] + (b[i]-a[i])
        defeat = b[i]-a[i]

if total > sum(a):
    print(sum(a))
else:
    print(total)

Submission status: Wrong Answer

Solution code:
n = int(input())
m = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]
y += [0]

remainder = 0
total = 0
for i in range(n+1):
    y[i] += remainder
    total += min(y[i], m[i])
    remainder = max(y[i] - m[i], 0)
print(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):
        mon = a[i] - tmp
        if b[i] <= mon:
            ans += b[i] + tmp
            tmp = 0
        else:
            ans += mon + tmp
            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())
M = list(map(int, input().split()))
H = list(map(int, input().split()))

sum_m = 0
rest = 0
for i in range(N):
  if M[i] >= H[i]+rest:
    rest = 0
    sum_m += H[i]+rest
  else:
    rest = min(H[i], H[i]+rest-M[i])
    sum_m += M[i]
sum_m += min(rest, M[-1])

print(sum_m)

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

Submission status: Wrong Answer

Solution code:
N = int(input())
M = list(map(int, input().split()))
H = list(map(int, input().split()))

sum_m = 0
killed = 0
rest = 0
for i in range(0, N):
  killed = min(H[i]+rest, M[i])
  rest = max(0, H[i]+rest-killed)
  sum_m += killed
sum_m += min(rest, M[-1])
print(sum_m)

Submission status: Wrong Answer

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

def f(ans,n):
    nn = min(a[n], b[n])
    nnn = min(a[n+1], b[n] - nn)
    a[n+1] -= nnn
    ans += nn
    ans += nnn

for i in range(n):
    f(ans, i)

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
M = list(map(int, input().split()))
H = list(map(int, input().split()))

sum_m = 0
killed = 0
rest = 0
for i in range(0, N):
  killed = min(H[i], M[i]-rest)
  rest = max(0, H[i]+rest-killed)
  sum_m += killed
sum_m += min(rest, M[-1])
print(sum_m)

Submission status: Wrong Answer

Solution code:
N = int(input())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))

ans = 0
tmp = 0
for a,b in zip(As,Bs[:N]):
    b += tmp
    if a >= b:
        ans += b
        tmp = 0
    else:
        ans += a
        tmp = b - a 
# 最後の町
a = As[N]
if a >= tmp:
    ans += tmp
else:
    ans += a

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))

ans = 0
tmp = 0
for a,b in zip(As,Bs[:N]):
    b += tmp
    if a >= b:
        ans += b
    else:
        b -= a 
        ans += a
    tmp = b
# 最後の町
a = As[N]
if a >= b:
    ans += b
else:
    ans += a

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

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
la = list(map(int,input().split()))
lb = list(map(int,input().split()))

total = 0
carry = 0
for i in range(n):
  total += carry

  tmp = la[i] - lb[i] - carry
  
  if tmp >= 0:
    carry = 0
    total += lb[i]
  else:
    carry = min(-tmp, la[i+1])
    total += la[i]

print(total)

Submission status: Wrong Answer

Solution code:
N = int(input())
M = list(map(int, input().split()))
H = list(map(int, input().split()))

sum_m = 0
killed = 0
rest = 0
for i in range(0, N):
  killed = min(H[i], M[i]-rest)
  rest = max(0, H[i]-killed)
  sum_m += killed
sum_m += min(rest, M[-1])
print(sum_m)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
a1 = []
res = []
for i in range(len(a)-1):
    a1.append(a[i]+a[i+1])
for i in range(len(b)):
    res.append(min(a1[i],b[i]))
print(sum(res))

Submission status: Wrong Answer

Solution code:
n = int(input())
la = list(map(int,input().split()))
lb = list(map(int,input().split()))

total = 0
carry = 0
for i in range(n):
  tmp = la[i] - lb[i] - carry
  
  if tmp >= 0:
    carry = 0
    total += lb[i]
  else:
    carry = min(-tmp, la[i+1])
    total += la[i] + carry


print(total+carry)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
count = 0
flag = 0
i = 0
while(i<len(a)-1):
	if b[i]<a[i]+a[i+1]:
		count = count+b[i]
		a[i+1] = a[i]+a[i+1]-b[i]
		flag = 0
		i += 1

	else:
		if flag == 0:
			count = count+a[i]+a[i+1]
			a[i+1] = 0
			flag = 1
			i = i + 1

		else:
			count = count + a[i+1]
			a[i+1] = 0
			i = 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()))
count = 0
for i in range(n-1,-1,-1):
    # i+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
    # iの討伐
    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:
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

A=list(reversed(A))
B=list(reversed(B))
cnt=0
tmp=0
for i in range(N):
    if A[i]>=B[i]:
        cnt+=B[i]
        tmp=0
    else:
        cnt+=A[i]
        tmp=min(B[i]-A[i],B[i])
        cnt+=tmp
        A[i+1]-=tmp
print(cnt)

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python

N = input()
N = int(N)

A = []
A = input().split()
A = [int(n) for n in A]
A.append(0)

B = []
B = input().split()
B = [int(n) for n in B]
B.append(0)
B.append(0)

#print('N=',n)
#print('A=',A)
#print('B=',B)

monster = 0

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

print(monster)

Submission status: Wrong Answer

Solution code:
N = int(input())
M = list(map(int, input().split()))
H = list(map(int, input().split()))

sum_m = 0
rest = 0
for i in range(0, N):
  killed = min(H[i], M[i]-rest)
  rest = max(0, H[i]+rest-M[i])
  sum_m = killed
sum_m += min(rest, M[-1])

print(sum_m)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python

N = input()
N = int(N)

A = []
A = input().split()
A = [int(n) for n in A]
A.append(0)

B = []
B = input().split()
B = [int(n) for n in B]
B.append(0)
B.append(0)

#print('N=',n)
#print('A=',A)
#print('B=',B)

monster = 0

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

print(monster)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
count = 0
flag = 0
i = 0
while(i<len(a)-1):
	if b[i]<a[i]+a[i+1]:
		count = count+b[i]
		flag = 0
		i += 1

	else:
		if flag == 0:
			count = count+a[i]+a[i+1]
			flag = 1
			i = i + 1

		else:
			count = count + a[i+1]
			i = i + 1
if count>sum(a):
	count = sum(a)
print(count)

Submission status: Wrong Answer

Solution code:
n,*a=map(int,open(0).read().split())
c=i=0
for b in a[:n]:i+=1;c+=min(b+a[i],a[n+i]);a[i]-=max(min(a[n+i]-b,a[i]),0)
print(c)

Submission status: Wrong Answer

Solution code:
n = int(input())
la = list(map(int,input().split()))
lb = list(map(int,input().split()))

total = 0
carry = 0
for i in range(n):
  tmp = la[i] - lb[i] - carry
  #print("tmp=",tmp,", carry=",carry)
  
  if tmp >= 0:
    carry = 0
    total += lb[i]
  else:
    carry = min(-tmp, la[i+1])
    total += la[i]

print(total+carry)

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

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

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

Submission status: Wrong Answer

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

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

print(point)

Submission status: Wrong Answer

Solution code:
#! /usr/bin/python
# -*- encoding: utf-8 -*-

import sys

if __name__ == '__main__':
    inputN = int(input())
    inputMonster = list(map(int, input().split()))
    inputPower = list(map(int, input().split()))

    sumVictory = 0
    zanMonster = inputMonster[-1]
    
    for i in range(inputN):
        # 末尾から，力量がモンスター数をうわまった場合，モンスター数を加算
        # そうでなければ，力量を加算し，一つ後の街の残りモンスター数を記録
        if inputPower[inputN - i - 1]  >= inputMonster[inputN - i - 1] + zanMonster:
            sumVictory += inputMonster[inputN - i - 1] + zanMonster
        
        else:
            sumVictory += inputPower[inputN - i - 1]
            if zanMonster > inputPower[inputN - i - 1]:
                zanMonster = inputMonster[inputN - i - 1]
            else:
                zanMonster = inputMonster[inputN - i - 1] + zanMonster - inputPower[inputN - i - 1]
        #print(sumVictory)
    sys.stdout.write(str(sumVictory))