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

Solution in C# (Mono 4.6.2.0) (judge verdict: Accepted)

using System;
using System.Numerics;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace debug
{
    class main
    {
        static void Main(string[] args)
        {
            //問題クラスを展開
            ProgramC a = new ProgramC();
            a.main();//実行する

        }

    }

    class ProgramA
    {
        public void main()
        {
            string[] input = Console.ReadLine().Split(' ');
            int A = int.Parse(input[0]);
            int B = int.Parse(input[1]);

            int K = A + B;

            if (K % 2 == 0)
                Console.WriteLine(K / 2);
            else
                Console.WriteLine("IMPOSSIBLE");

        }
    }

    class ProgramB
    {
        public void main()
        {
            //入力
            string input = Console.ReadLine();
            int n = int.Parse(input);
            string[] input_p = Console.ReadLine().Split(' ');
            int[] p = new int[n];
            for (int i = 0; i < n; i++)
                p[i] = int.Parse(input_p[i]);

            int count = 0;

            for (int i = 0; i < n; i++)
            {
                if (p[i] != i + 1)
                    count++;
            }

            if (count == 2 || count == 0)
                Console.WriteLine("YES");
            else
                Console.WriteLine("NO");

        }
    }

    class ProgramC
    {
        public void main()
        {
            //入力
            string input = Console.ReadLine();
            int n = int.Parse(input);

            string[] input_a = Console.ReadLine().Split(' ');
            long[] a = new long[n + 1];
            for (int i = 0; i < n + 1; i++)
                a[i] = long.Parse(input_a[i]);

            string[] input_b = Console.ReadLine().Split(' ');
            long[] b = new long[n];
            for (int i = 0; i < n; i++)
                b[i] = long.Parse(input_b[i]);

            long count = 0;

            for (int i = 0; i < n; i++)
            {
                //二人を集計して比較、
                count += Math.Min(a[i] + a[i + 1], b[i]);
                //倒しきれない場合はa[i + 1]を0にして次へ
                if(a[i] <= b[i])
                    a[i + 1] = Math.Max(a[i + 1] - (b[i] - a[i]), 0);

            }

            //答え出力
            Console.WriteLine(count);
        }



    }
    
    class ProgramD
    {
        public void main()
        {
            //入力
            string[] s = Console.ReadLine().Split(' ');
            int n = int.Parse(s[0]);
            int m = int.Parse(s[1]);

            //これらはインスタンスが作られていないのであらかじめ作る
            List<int>[] test = new List<int>[100000];

            //インスタンスを入れる
            for (int i = 0; i < 100000; i++)
                test[i] = new List<int>();


            //リストを入れておく
            for (int i = 0; i < m; i++)
            {
                string[] t = Console.ReadLine().Split(' ');
                int a = int.Parse(t[0]);
                int b = int.Parse(t[1]);
                test[a - 1].Add(b - 1);
                test[b - 1].Add(a - 1);
            }

            Queue<int> q = new Queue<int>();
            int[] ans = new int[n - 1];

            //最初のキューを入れておく
            for (int j = 0; j < test[0].Count(); j++)
            {
                q.Enqueue(test[0][j]);
                ans[test[0][j] - 1] = 1;
            }

            //全経路探るまで続ける
            while (q.Count != 0)
            {
                //次の推移の候補場所を出す
                for(int i = 0; i < q.Count;i++)
                {
                    int k = q.Dequeue();

                    //次の候補場所が未検索であればキューに入れておく
                    for (int j = 0; j < test[k].Count(); j++)
                    {
                        //1に戻る場合は飛ばす（相互関係によって起こるのでそれを防ぐ）
                        if (test[k][j] == 0)
                            continue;

                        //もし未検索ならキューを入れる
                        if (ans[test[k][j] - 1] == 0)
                        {
                            q.Enqueue(test[k][j]);
                            ans[test[k][j] - 1] = k + 1;//添え字に注意（ans内は2からなのでもう1引く、kは1引いた状態なので1足して戻す
                        }
                    }

                }

            }

            //あり得ないケースはないので、yesして答を出す
            Console.WriteLine("Yes");
            for (int i = 0; i < n - 1; i++)
                Console.WriteLine(ans[i]);

        }
    }

    

    class ProgramE
    {
        public void main()
        {
            int n = int.Parse(Console.ReadLine());
            string[] s = Console.ReadLine().Split(' ');
            int[] a = new int[n];

            for (int i = 0; i < n; i++)
                a[i] = int.Parse(s[i]) - 1;

            for (int i = 0; i < n; i++)
            {
                int temp = a[a[i]];
                int count = 1;
                while (a[i] != temp)
                {
                    temp = a[temp];
                    count++;

                }

                Console.Write(count + " ");
            }
        }


    }

    
}