unittest
{
	assert( [ "2", "3 5 2", "4 5" ].parse.expand.solve == 9 );
	assert( [ "3", "5 6 3 8", "5 100 8" ].parse.expand.solve == 22 );
	assert( [ "2", "100 1 1", "1 100" ].parse.expand.solve == 3 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	input.popFront;
	auto as = input.front.split.to!( long[] );
	input.popFront;
	auto bs = input.front.split.to!( long[] );
	return tuple( as, bs );
}

auto solve( long[] as, long[] bs )
{
	auto ans = 0L;
	auto r = 0L;
	bs ~= 0;
	foreach( a, b; lockstep( as, bs ) )
	{
		auto m = min( a, r + b );
		r = b - max( 0, m - r );
		ans += m;
	}
	return ans;
}
