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: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import sys
import itertools#これは色々使える組み込み関数みたいなやつ
#import math#数学的計算はこれでいける。普通に0.5乗しても計算可能
#w=input()
from operator import itemgetter
from sys import stdin
#input = sys.stdin.readline#こっちの方が入力が早いが使える時に使っていこう
#これもdpで考えるべきだったかも
N=3
M=3
i=0
j=0
k=0
ans=0


N=int(input())
#A=int(input())
#B=int(input())
#print(N)
monster_list=list(map(int, input().split(" ")))#数字の時
beat_list=list(map(int, input().split(" ")))#数字の時
#print(monster_list)
#print(beat_list)

for i in reversed(range(N+1)):#逆回しで値を代入しているよ
 print(i)
 print(monster_list)
 print(beat_list)
 if i >=1:
    if beat_list[i-1]<monster_list[i]:#倒せる数がモンスターの数より少ない時
        ans=ans+beat_list[i-1]
        beat_list[i-1]=0
    else:#倒せる数がモンスターの数より多い時
        beat_list[i-1]=beat_list[i-1]-monster_list[i]
        ans=ans+monster_list[i]
        monster_list[i]=0
        if beat_list[i-1]>=monster_list[i-1]:#自分の街まで処理しきれる時
            ans=ans+monster_list[i-1]

        else:#自分の街までは無理な時
            ans=ans+beat_list[i-1]
            monster_list[i-1]=monster_list[i-1]-beat_list[i-1]

 # else:
 #     if beat_list[i]>=monster_list[i]:
 #         ans=ans+monster_list[i]

 #     else:
 #         ans=ans+beat_list[i]
print(ans)

"1行1つの整数を入力を取得し、整数と取得する"


#number_list=list(map(int, input().split(" ")))#数字の時
#print(number_list)
"12 21 332 とか入力する時に使う"
"1行に複数の整数の入力を取得し、整数として扱う"

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
#メモ
for i in number_list:#こっちの方がrage使うより早いらしい
    print(number_list[i-1])

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'''
x=[]
y=[]
for i in range(N):
    x1, y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)
print(x)
print(y)
"複数行に2数値を入力する形式 x座標とy座標を入力するイメージ"
'''

'''
mixlist=[]
for i in range(N):
    a,b=input().split()
    mixlist.append((int(a),b))
print(mixlist)
"複数行にintとstrを複合して入力するやつ，今回はリスト一つで処理している"
#1 a
#2 b
とかに使う
'''

'''
#array=[input().split()for i in range(N)]
#print(type(array[0][0]))
#print(array)
"正方行列にstr型の値を入力"
'''

#brray=[list(map(int, input().split(" ")))for i in range(N)]
#print(type(brray[0][0]))
#print(brray)
'''
入力
1 2
4 5
7 8
出力結果
[[1, 2], [4, 5], [7, 8]]
'''
"列数に関して自由度の高いint型の値を入力するタイプの行列"
#以下に別解を記載
#N, M = [int(i) for i in input().split()]
'''
table = [[int(i) for i in input().split()] for m in range(m)]

print(type(N))
print(N)
print(type(M))
print(M)

print(type(table))
print(table)
'''




#s=input()
#a=[int(i) for i in s]
#print(a[0])
#print([a])
#単数値．桁ごとに分割したい．入力と出力は以下の通り
#イメージとして1桁ごとにリストに値を入れているかんじ

'''
入力
1234
出力
1
[[1, 2, 3, 4]]
'''




'''
word_list= input().split(" ")
print(word_list[0])
"連続文字列の入力"
"qw er ty とかの入力に使う"
"入力すると空白で区切ったところでlistの番号が与えられる"
'''



'''
A, B, C=stdin.readline().rstrip().split()#何個でもいけることが多い
print(A)
"リストではなく独立したstr型を入れるなら以下のやり方でOK"
'''


#a= stdin.readline().rstrip()
#print(a.upper())
"aという変数に入っているものを大文字にして出力"




#なんかうまく入力されるけど
#a=[[int(i) for i in 1.strip()]for 1 in sys.stdin]
#a = [[int(c) for c in l.strip()] for l in sys.stdin]]
#print(a)
#複数行の数値を入力して正方行列を作成

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
#include<bits/stdc++.h>
using namespace std;

int main(){
    int N,ans=0;
    cin>>N;
    vector<int>A(N+1),B(N);
    for(int i=0;i<N+1;i++){
        cin>>A.at(i);
    }
    for(int i=0;i<N;i++){
        cin>>B.at(i);
    }
    
    for(int i=0;i<N;i++){
        if(A.at(i)+A.at(i+1)<=B.at(i)){
            ans += A.at(i)+A.at(i+1);
            A.at(i) = 0;
            A.at(i+1) = 0;
        }else if(A.at(i)>=B.at(i)){
            ans += B.at(i);
            A.at(i) -= B.at(i);
        }else if(A.at(i)<B.at(i)&&A.at(i)+A.at(i+1)>=B.at(i)){
            ans += B.at(i);
            A.at(i+1) -= B.at(i) - A.at(i);
            A.at(i) = 0;
        }
    }
    
    cout<<ans<<endl;
}

Submission status: Runtime Error

Solution code:
ans=0
right=0
left=0
for i in range(n):
    left=min(a[i],b[i])
    ans+=left
    a[i]-=left
    b[i]-=left
    
    right=min(a[i+1],b[i])
    ans+=right
    a[i+1]-=right
    b[i]-=right
print(ans)

Submission status: Runtime Error

Solution code:
ns=0
right=0
left=0
for i in range(n):
    left=min(a[i],b[i])
    ans+=left
    a[i]-=left
    b[i]-=left
    
    right=min(a[i+1],b[i])
    ans+=right
    a[i+1]-=right
    b[i]-=right
print(ans)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A = [int(a) for a in input().split()]
B = [int(b) for b in input().split()]
ans = 0
mons = 0
yusha = 0
for i in range(N):
	mons = max(A[i] - yusha, 0)
    ans += min(yusha, A[i])
    ans += min(mons, B[i])
    yusha = max(0, B[i] - mons)
print(ans)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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


# Imperative solution
# res = 0
# rem = 0

# for i in range(N):
#     mobs_rem = min(A[i], rem)
#     A[i] -= mobs_rem
#     mobs = min(A[i], B[i])
#     rem = B[i] - mobs
#     res += (mobs+mobs_rem)

# res += min(A[N], rem)
# print(res)

# Functional
def rec(idx, res, rem):
    if idx == N:
        res += min(A[idx], rem)
        return res
    mobs_rem = min(A[idx], rem)
    mobs = min(A[idx] - mobs_rem, B[idx])
    rem = B[idx] - mobs
    res += (mobs + mobs_rem)
    return rec(idx+1, res, rem)


print(rec(0, 0, 0))

Submission status: Runtime Error

Solution code:
def main():
  import sys
  n = int(input())
  a = list(map(int.sys.stdin.readline().split()))
  b = list(map(int.sys.stdin.readline().split()))
  
  count=0
  
  for i in range(n):
    c1 = a[i] 
    c2 = a[i+1]
    h = b[i]
    ans+=min(c1,h)  
    if h>c1:
        ans+=min(h-c1,c2)
        a[i+1]=max(0,c2-(h-c1))

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

Submission status: Runtime Error

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

rest = 0
c = 0
for i in range(n):
    c += min(rest,a[i])
    c += min(max(0,a[i] - rest),b[i])
    rest = max(0, b[i] - a[i])
    
c += min(rest,a[i])
print(c)

Submission status: Runtime Error

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



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

print(sum(c))

Submission status: Runtime Error

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



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

print(c,sum(c))

Submission status: Runtime Error

Solution code:
#

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

print(z)

Submission status: Runtime Error

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



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

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
res = 0
for i in range(n):
    t1 = min(a[i], b[i])
    a[i] -= t1
    b[i] -= t1
    res += t
    t2 = min(a[i+1], b[i])
    a[i+1] -= t2
    b[i] -= t2
    res += t2
print(res)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())

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

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

Submission status: Runtime Error

Solution code:
n = int(input())

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

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

Submission status: Runtime Error

Solution code:
n=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
remain=A[0]
ans1=0
for i in range(n):
    if B[i]<=remain:
        ans1+=B[i]
        remain=A[i+1]
    if B[i]>remain:
        ans1+=remain
        yoryoku=B[i]-remain
        if yoryoku>A[i+1]:
            ans1+=A[i+1]
            remain=0
        else:
            ans1+=yoryoku
            remain=A[i+1]-yoryoku
rA=reversed(A)
rB=reversed(B)
remain=rA[0]
ans2=0
for i in range(n):
    if rB[i]<=remain:
        ans2+=rB[i]
        remain=rA[i+1]
    if rB[i]>remain:
        ans2+=remain
        yoryoku=rB[i]-remain
        if yoryoku>rA[i+1]:
            ans2+=rA[i+1]
            remain=0
        else:
            ans2+=yoryoku
            remain=rA[i+1]-yoryoku
print(max(ans1,ans2))

Submission status: Runtime Error

Solution code:
b=[int(i) for i in input().split()]
sum=np.sum(b)
for i in reversed(range(n)):
  k = a[i+1]
  l = a[i]
  m = b[i]
 
  a[i+1] = max(k-m, 0)
  b[i] = max(m-k, 0)
 
  a[i] = max(l-b[i], 0)
  b[i] = max(b[i]-l, 0)
postsum=np.sum(b)
print(sum-postsum)

Submission status: Runtime Error

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

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

print(fenum - sum(A))

Submission status: Runtime Error

Solution code:
#n = int(input())
#L = list(map(int, input().split()))
import math
import sys
import heapq
import fractions
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ans = 0

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

print(ans)

Submission status: Runtime Error

Solution code:
#n = int(input())
#L = list(map(int, input().split()))
import math
import sys
import heapq
import fractions
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ans = 0

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

print(ans)

Submission status: Runtime Error

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

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

print(c)

Submission status: Runtime Error

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

ans = 0
for i,b in enumerate(B):
    temp = min(b,A[i]+A[i+1])
    ans += temp
    A[i+1] -= max(0, temp-A[i]) #有り余った力を次の街で倒す
print(an)

Submission status: Runtime Error

Solution code:
n=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
m=0
t=len(B)
for i in range(t)
if a[i]>=b[i]:
  m+=b[i]
  if a[i]-b[i]>=b[i+1]:
    m+=b[i+1]
    b[i+1]=0
  else:
    m+=a[i]-b[i]
    b[i+1]-=a[i]-b[i]
else:
  m+=a[i]

Submission status: Runtime Error

Solution code:
cnt = 0
ans = 0

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

print(ans)

Submission status: Runtime Error

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

print(cnt)

Submission status: Runtime Error

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

if(int(A[N]) - int(B[N-1]) > 0):
  mon = mon + (int(A[N]) - int(B[N-1]))

else:
  mon = mon + (int(B[N-1]) - int(A[N]))

print(mon)

Submission status: Runtime Error

Solution code:
Last login: Tue Oct 15 13:38:16 on ttys000
h0104hand023:~ atsu.handa$ ls
-H		Desktop		Library		Pictures	m.txt
-d		Documents	Movies		Public		tt.txt
Applications	Downloads	Music		get-pip.py
h0104hand023:~ atsu.handa$ cd Desktop/
h0104hand023:Desktop atsu.handa$ s
-bash: s: command not found
h0104hand023:Desktop atsu.handa$ ls
Commvault自動化概要 - Google スライド_files
FW
GCP
key
propro
receipt_LPIC101.pdf
work
業務（完了済）2019
スクリーンショット 2019-07-31 11.15.05.png
スクリーンショット 2019-08-01 14.24.31.png
スクリーンショット 2019-08-09 17.09.06.png
スクリーンショット 2019-09-13 17.31.08.png
h0104hand023:Desktop atsu.handa$ cd propro/
h0104hand023:propro atsu.handa$ ls
1			atksur.cpp		go_to_school.py
1q			disjoint.py		lower.py
a.out			divide_problems.py	tapdance.cpp
alchemist.py		exception.py		transportations.py
h0104hand023:propro atsu.handa$ grep input
*.py
^C
h0104hand023:propro atsu.handa$ 
h0104hand023:propro atsu.handa$ 
h0104hand023:propro atsu.handa$ grep input *.py
alchemist.py:N = int(input())
alchemist.py:V = [int(i) for i in input().split()]
disjoint.py:S = list(map(int,input().split()))
divide_problems.py:N = int(input())
divide_problems.py:D = list(map(int,input().split()))
exception.py:N = int(input())
exception.py:A = [input() for _ in range(N)]
go_to_school.py:N = int(input())
go_to_school.py:S = list(map(int,input().split()))
lower.py:N = int(input())
lower.py:H = list(map(int,input().split()))
transportations.py:N = int(input())
transportations.py:A = int(input())
transportations.py:B = int(input())
transportations.py:C = int(input())
transportations.py:D = int(input())
transportations.py:E = int(input())
h0104hand023:propro atsu.handa$ vi exception.py 
h0104hand023:propro atsu.handa$ cp exception.py ./city_savers.py
h0104hand023:propro atsu.handa$ vi city_savers.py 
h0104hand023:propro atsu.handa$ python city_savers.py 
2
3
5
2
4
5
Traceback (most recent call last):
  File "city_savers.py", line 7, in <module>
    mon[i] = B[i] - A[i]
TypeError: unsupported operand type(s) for -: 'str' and 'str'
h0104hand023:propro atsu.handa$ vi city_savers.py 
h0104hand023:propro atsu.handa$ python city_savers.py 
2
3 5 2
4 5


a
Traceback (most recent call last):
  File "city_savers.py", line 7, in <module>
    mon[i] = int(B[i]) - int(A[i])
ValueError: invalid literal for int() with base 10: ''
h0104hand023:propro atsu.handa$ s
-bash: s: command not found
h0104hand023:propro atsu.handa$ vi city_savers.py 
h0104hand023:propro atsu.handa$ vi city_savers.py 
h0104hand023:propro atsu.handa$ python city_savers.py 
2
3 5 2
4 5



Traceback (most recent call last):
  File "city_savers.py", line 7, in <module>
    mon[i] = int(B[i]) - int(A[i])
ValueError: invalid literal for int() with base 10: ''
h0104hand023:propro atsu.handa$ 
h0104hand023:propro atsu.handa$ python city_savers.py 
2
3 5 2
4 5



Traceback (most recent call last):
  File "city_savers.py", line 7, in <module>
    mon[i] = int(B[i]) - int(A[i])
ValueError: invalid literal for int() with base 10: ''
h0104hand023:propro atsu.handa$ vi city_savers.py 
h0104hand023:propro atsu.handa$ python city_savers.py 
2
3 5 2
4 5



Traceback (most recent call last):
  File "city_savers.py", line 4, in <module>
    mon
NameError: name 'mon' is not defined
h0104hand023:propro atsu.handa$ vi city_savers.py 
h0104hand023:propro atsu.handa$ python city_savers.py 
2
3 5 2
4 5

Traceback (most recent call last):
  File "city_savers.py", line 7, in <module>
    mon[i] = int(B[i]) - int(A[i])
ValueError: invalid literal for int() with base 10: ''
h0104hand023:propro atsu.handa$ vi city_savers.py 
h0104hand023:propro atsu.handa$ python city_savers.py 
^CTraceback (most recent call last):
  File "city_savers.py", line 1, in <module>
    N = int(input())
KeyboardInterrupt
h0104hand023:propro atsu.handa$ 
h0104hand023:propro atsu.handa$ 
h0104hand023:propro atsu.handa$ grep input *.py
alchemist.py:N = int(input())
alchemist.py:V = [int(i) for i in input().split()]
city_savers.py:N = int(input())
city_savers.py:A = [input() for _ in range(N)]
city_savers.py:B = [input() for _ in range(N-1)] 
disjoint.py:S = list(map(int,input().split()))
divide_problems.py:N = int(input())
divide_problems.py:D = list(map(int,input().split()))
exception.py:N = int(input())
exception.py:A = [input() for _ in range(N)]
go_to_school.py:N = int(input())
go_to_school.py:S = list(map(int,input().split()))
lower.py:N = int(input())
lower.py:H = list(map(int,input().split()))
transportations.py:N = int(input())
transportations.py:A = int(input())
transportations.py:B = int(input())
transportations.py:C = int(input())
transportations.py:D = int(input())
transportations.py:E = int(input())
h0104hand023:propro atsu.handa$ vi alchemist.py 
h0104hand023:propro atsu.handa$ vi alchemist.py 
h0104hand023:propro atsu.handa$ vi city_savers.py 
h0104hand023:propro atsu.handa$ python city_savers.py 
2
3 5 2
4 5
Traceback (most recent call last):
  File "city_savers.py", line 7, in <module>
    mon[i] = int(B[i]) - int(A[i])
TypeError: 'tuple' object does not support item assignment
h0104hand023:propro atsu.handa$ vi city_savers.py 
h0104hand023:propro atsu.handa$ python city_savers.py 
2
3 5 2
4 5
Traceback (most recent call last):
  File "city_savers.py", line 7, in <module>
    mon[i] = int(B[i]) - int(A[i])
IndexError: list assignment index out of range
h0104hand023:propro atsu.handa$ vi city_savers.py 
h0104hand023:propro atsu.handa$ python city_savers.py 
2
3 5 2
4 5
1
0
h0104hand023:propro atsu.handa$ vi city_savers.py 
h0104hand023:propro atsu.handa$ python city_savers.py 
  File "city_savers.py", line 9
    int(B[i+1]) = int(B[i+1]) - ( int(B[i]) - int(A[i]) )
    ^
SyntaxError: can't assign to function call
h0104hand023:propro atsu.handa$ 2
-bash: 2: command not found
h0104hand023:propro atsu.handa$ 3 5 
h0104hand023:propro atsu.handa$ vi city_savers.py 
h0104hand023:propro atsu.handa$ python city_savers.py 
2
3 5 2
4 5
7
h0104hand023:propro atsu.handa$ vi city_savers.py 
h0104hand023:propro atsu.handa$ python city_savers.py 
2
3 5 2
4 5
Traceback (most recent call last):
  File "city_savers.py", line 13, in <module>
    mon = mon + (int(A[N+1]) - int(B[N]))
IndexError: list index out of range
h0104hand023:propro atsu.handa$ vi city_savers.py 
h0104hand023:propro atsu.handa$ python city_savers.py 
2
3 5 2
4 5
5
h0104hand023:propro atsu.handa$ vi city_savers.py 
h0104hand023:propro atsu.handa$ python city_savers.py 
2
3 5 2
4 5
5
h0104hand023:propro atsu.handa$ vi city_savers.py 
h0104hand023:propro atsu.handa$ python city_savers.py 
2
3 5 2
4 5
9
h0104hand023:propro atsu.handa$ vi city_savers.py 

N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
ret = [0] * N
mon = 0
for i in range(0, N):
  if(int(B[i]) - int(A[i]) >= 0 ):
    mon = mon + int(A[i])
    B[i+1] = int(B[i+1]) - ( int(B[i]) - int(A[i]) )
  else:
    mon = mon + int(B[i])

if(int(A[N]) - int(B[N-1]) > 0):
  mon = mon + (int(A[N]) - int(B[N-1]))

else:
  mon = mon + (int(B[N-1]) - int(A[N]))

print(mon)

Submission status: Runtime Error

Solution code:
n=int(raw_input())
g=raw_input().split()
a=[int(x) for x in g]
g=raw_input().split()
b=[int(x) for x in g]
#n=len()
acc=0
for i in range(n):
	inc=min(a[i],b[i])
	a[i]-=inc
	b[i]-=inc
	acc+=inc
	print(a,b,inc)
	inc=min(a[i+1],b[i])
	a[i+1]-=inc
	b[i]-=inc
	acc+=inc
	print(a,b,inc)
print(acc)

Submission status: Runtime Error

Solution code:
N = int(input())
A = [int(_) for _ in input().split()]
B = [int(_) for _ in input().split()]
def_Bsum = sum(B)
 
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
 
    if(0<i<N):
        if(A[i] < B[i-1]):
            B[i-1] -= A[i]
            A[i] = 0
        else:
            A[i] -= B[i-1]
            B[i-1] = 0
 
            if (A[i] < B[i]):
                B[i] -= A[i]
                A[i] = 0
            else:
                A[i] -= B[i]
                B[i] = 0
 
    if(i==N):
        if (A[i] < B[i-1]):
            B[i-1] -= A[i]
            A[i] = 0
        else:
            A[i] -= B[i-1]
            B[i-1] = 0
 
 
ans = def_Bsum - sum(B)

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A = [int(_) for _ in input().split()]
B = [int(_) for _ in input().split()]
def_Bsum = sum(B)
 
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
 
    if(0<i<N):
        if(A[i] < B[i-1]):
            B[i-1] -= A[i]
            A[i] = 0
        else:
            A[i] -= B[i-1]
            B[i-1] = 0
 
            if (A[i] < B[i]):
                B[i] -= A[i]
                A[i] = 0
            else:
                A[i] -= B[i]
                B[i] = 0
 
    if(i==N):
        if (A[i] < B[i-1]):
            B[i-1] -= A[i]
            A[i] = 0
        else:
            A[i] -= B[i-1]
            B[i-1] = 0
 
 
ans = def_Bsum - sum(B)

print(ans)

Submission status: Runtime Error

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

c = 0
for i in range(n):
      ci = 0
      ci = min(a[i],b[i])
      c += ci
      b[i] -= ci
      ci1 = 0
      ci1 = min(a[i+1],b[i])
      c += ci1
      c[i+1] -= ci1

print(c)

Submission status: Runtime Error

Solution code:
n = int(input())
L1 = list(map(int,input().split()))
L2 = list(map(int,input().split()))

ans = 0
for i in range(n):
      ans += min(L2[i],L1[i]+L1[i+1])
      L1[i+1] = max(0,L1[i+1] - max(0,(L2[i]-L1[i])))
print(c)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,e) for(int i= 0; i< (int)(e); i++)
#define reps(i,s,e) for(int i = s; i < (int)(e); i++)
#define repr(i,s,e) for(int i = s; i > (int)(e); i--)
typedef long long ll;

int main(){
	int n;
	cin >> n;
	vector<ll> a(n+1);
	vector<ll> b(n);
	rep(i,n+1) cin >> a[i];
	rep(i,n) cin >> b[i];
	ll taosu = 0;
	rep(i,n){
		ll ltaosu = min(a[i],b[i]);
		ll rtaosu = min(a[i+1],b[i]-ltaosu);
		a[i] -= ltaosu;
		a[i+1] -= rtaosu;
		taosu += ltaosu + rtaosu;
	}
	cout << taosu;

}

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

count = 0

for i in range(N+1):
    if i > 0:
        if (A[i] > 0) and (B[i-1] > 0):
            tmp = min(A[i],B[i-1])
            count += tmp
            A[i] -= tmp
            B[i-1] -= tmp            

    if (A[i] > 0) and (B[i] > 0):
        tmp = min(A[i],B[i])
        count += tmp
        A[i] -= tmp
        B[i] -= tmp

print(count)

Submission status: Runtime Error

Solution code:
#135c
N = str(input())
list_A = list(map(int, input().split()))
list_B = list(map(int, input().split()))

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

ans = 0
remaining_power = 0

if N>1:
    for i in range(N-1,-1,-1):
        #print(i,"… RP:",remaining_power,",A:",list_A[i+1],",B:",list_B[i])

        if remaining_power>list_A[i+1]:
            #余力のみで倒せる
            remaining_power=list_B[i]
            ans += list_A[i+1]
            #print("margin")
        elif remaining_power + list_B[i] > list_A[i+1]:
            #余力と勇者で倒せる
            remaining_power = list_B[i] - (list_A[i+1] - remaining_power)
            ans += list_A[i+1]
            #print("OK")
        else:
            #余力と勇者でも倒せない
            ans += remaining_power + list_B[i]
            remaining_power = 0
            #print("No")
else:
    remaining_power = list_B[0] 
            
if remaining_power > list_A[0]:
    ans += list_A[0]
else:
    ans += remaining_power
        
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
    
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
    
ans = 0
for i in range(n):
  if a[i] <= b[i]:
    ans += a[i]
    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: Runtime Error

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

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())
a = input().split() #N+1
b = input().split() #N
for l in range(2):
  b.append(0)
for num in range(N+2):
  a[num] = int(a[num])
  b[num] = int(b[num])
n = 0
for i in range(N+1):
  if a[i] >= b[i]:
    n += b[i]
  else:
    n += a[i]
    b[i+1] += (b[i] - a[i])
print(n)

Submission status: Runtime Error

Solution code:
N = int(input())
a = input().split()
b = input().split()
for l in range(2):
  b.append(0)
n = 0
for i in range(N+1):
  if int(a[i]) >= int(b[i]):
    n += int(b[i])
  else:
    n += int(a[i])
    int(b[i+1]) += (int(b[i]) - int(a[i]))
print(n)

Submission status: Runtime Error

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

Submission status: Runtime Error

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] + a[i+1] <= b[i]:
    s += a[i] + a[i+1]
    a[i+1] = 0
  elif a[i] + a[i+1] > b[i] and a[i] <= b[i]:
    s += b[i]
    a[i+1] -= b[i] - a[i]
  elif a[i] > b[i]:
    s += a[i]
print(s)