//==================================================================================================
// Name        : C.cpp
// Author      : lotus.eater086
// Copyright   : If you're reading this then this warning is for you. Every word you read of this 
//               useless fine print is another second of your life. Don't you've other things to do?
//               Is your life so empty that you honestly can't think of a better way to spend these
//               moments ? Or are you so impressed with authority that you give respect and 
//               credence to all who claim it ? Do you read everything you're supposed to read ? Do
//               you think everything you're supposed to think ? Buy what you're told you should 
//               want ? Get out of your apartment . Meet a member of the opposite sex. Stop the 
//               excessive shopping and self-improvement . Quit your boring job.
//               Start a fight. Prove you're alive. If you don't claim your humanity you'll become a
//               statistic. You've been warned !

// Description : 
// Date        : 2019-07-27
// Time        : 18:28:07
// Directory   : c:\Users\Lenovo\cpPractise\deliberatePractise\code_folder
// FilePath    : c:\Users\Lenovo\cpPractise\deliberatePractise\code_folder\C.cpp
//==================================================================================================
    

#include <bits/stdc++.h>
#define LL long long
#define endl "\n"

using namespace std ;
    
//
template < typename T >

inline T read( T &x )
{

    x = 0 ;

    int f = 0 ;

    char ch = getchar() ;

    while( ch < '0' || ch > '9' )  {

        f |= ( ch == '-' ) , ch = getchar() ;

    }

    while( ch >= '0' && ch <= '9' )  {

        x = ( x << 1 ) + ( x << 3 ) + ch - '0' , ch = getchar() ;

    }

    return x = f ? -x:x ;

}
//

int main( void )

{

    //ios_base::sync_with_stdio( false ) ;  cin.tie( NULL ) ;  cout.tie( NULL ) ;

  //  #ifndef ONLINE_JUDGE
     //   freopen( "input.txt" , "r" , stdin ) ;
     //   freopen( "output.txt" , "w" , stdout ) ;
  //  #endif

    int n ;

    read( n ) ;

    int M = n+1 ;

    vector<LL> monster(M) , hero(n) ;

    for( int i = 0 ; i < M ; i++ )  read( monster[i] ) ;

    for( int i = 0 ; i < n ; i++ )  read( hero[i] ) ;

    LL cnt = 0 ;

    for( int i = 0 ; i < n ; i++ )  {

        if( monster[i] <= hero[i] )  {

            cnt += monster[i] ; 

            hero[i] -= monster[i] ;

            monster[i] = 0 ;

            if( hero[i] == 0 )  continue ;

            if( monster[i+1] < hero[i] )  {

                cnt += monster[i+1] ;

                monster[i+1] = 0 ;

                hero[i] -= monster[i+1] ; 

            }

            else if( monster[i+1] == hero[i] )  {

                cnt += monster[i+1] ;  

                monster[i+1] = 0 ;

                hero[i] = 0 ;

            }

            else  {

                cnt = cnt + ( hero[i] ) ;  

                monster[i+1] -= hero[i] ;

                hero[i] = 0 ;

            }

        }

        else  {

            cnt = cnt + hero[i] ;

            monster[i] -= hero[i] ;

            hero[i] = 0 ;

        }

    }

    cout << cnt << endl ;

   

    return 0 ;

}


Measured memory_bytes: 1792