let n = Scanf.scanf " %d" (+) 0
let a_s = Array.init (n + 1) @@ fun _ -> Scanf.scanf " %d" (+) 0
let bs = Array.init n @@ fun _ -> Scanf.scanf " %d" (+) 0
let r, ans = ref a_s.(0), ref 0
let _ = Array.iteri (fun i b -> ans := !ans + min b (!r + a_s.(i + 1)); r := max 0 @@ a_s.(i + 1) - (b - min !r b)) bs; Printf.printf "%d\n" !ans