Language: C++

#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
//long long…2^64-1 = 9223372036854775807まで

void _main() {
	int N;
	cin >> N;

	vector<int> A(N+1);
	rep(i, 0, N+1) cin >> A[i];
	vector<int> B(N);
	rep(i, 0, N) cin >> B[i];

	int count = 0;
	rep(i, 0, N) {
		count += B[i];
	}

	rep(i,0,N){
		A[i] -= B[i];
		if (A[i] < 0) A[i + 1] += A[i];

		if (A[i + 1] < 0) {
			count += A[i + 1];
			A[i + 1] = 0;

		}
	}

	cout << count << endl;

}

Compiler output:
a.cc: In function 'int main()':
a.cc:6:49: error: 'cin' was not declared in this scope
    6 | using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
      |                                                 ^~~
a.cc:1:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
  +++ |+#include <iostream>
    1 | #define rep(i,a,b) for(int i=a;i<b;i++)
a.cc:6:61: error: 'ios' has not been declared
    6 | using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
      |                                                             ^~~
a.cc: At global scope:
a.cc:7:39: error: 'INT_MAX' was not declared in this scope
    7 | typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
      |                                       ^~~~~~~
a.cc:1:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
  +++ |+#include <climits>
    1 | #define rep(i,a,b) for(int i=a;i<b;i++)
a.cc: In function 'void _main()':
a.cc:15:9: error: 'cin' was not declared in this scope
   15 |         cin >> N;
      |         ^~~
a.cc:15:9: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:17:9: error: 'vector' was not declared in this scope
   17 |         vector<int> A(N+1);
      |         ^~~~~~
a.cc:1:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
  +++ |+#include <vector>
    1 | #define rep(i,a,b) for(int i=a;i<b;i++)
a.cc:17:16: error: expected primary-expression before 'int'
   17 |         vector<int> A(N+1);
      |                ^~~
a.cc:18:31: error: 'A' was not declared in this scope
   18 |         rep(i, 0, N+1) cin >> A[i];
      |                               ^
a.cc:19:16: error: expected primary-expression before 'int'
   19 |         vector<int> B(N);
      |                ^~~
a.cc:20:29: error: 'B' was not declared in this scope
   20 |         rep(i, 0, N) cin >> B[i];
      |                             ^
a.cc:24:26: error: 'B' was not declared in this scope
   24 |                 count += B[i];
      |                          ^
a.cc:28:17: error: 'A' was not declared in this scope
   28 |                 A[i] -= B[i];
      |                 ^
a.cc:28:25: error: 'B' was not declared in this scope
   28 |                 A[i] -= B[i];
      |                         ^
a.cc:38:9: error: 'cout' was not declared in this scope
   38 |         cout << count << endl;
      |         ^~~~
a.cc:38:9: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:38:26: error: 'endl' was not declared in this scope
   38 |         cout << count << endl;
      |                          ^~~~
a.cc:1:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
  +++ |+#include <ostream>
    1 | #define rep(i,a,b) for(int i=a;i<b;i++)