Language: C++

#include "bits/stdc++.h"
using namespace std;

typedef long long ll;

int main()
{
	int n;

	cin >> n;
	vector<ll> a(n + 1);		// 葉
	vector<ll> mae(n + 1, 1);	// 前から見た時の最大頂点数
	vector<ll> ushiro(n + 1);	// 後ろから見た時の最大頂点数
	for (int i = 0; i <= n; i++) {
		cin >> a.at(i);
	}

	if (n == 0) {
		if (a.at(0) == 1) {
			cout << 1 << endl;
		} else {
			cout << -1 << endl;
		}
		return 0;
	}

	for (int i = 1; i <= n; i++) {
		mae.at(i) = min((mae.at(i - 1) - a.at(i - 1)) * 2);
		if (mae.at(i) < 0) {
			cout << -1 << endl;
			return 0;
		}
	}

	ushiro.at(n) = a.at(n);
	for (int i = n - 1; i >= 0; i--) {
		ushiro.at(i) = min(ushiro.at(i + 1) + a.at(i));
	}

	ll ans = 0;
	for (int i = 0; i <= n; i++) {
		ll temp = min(mae.at(i), ushiro.at(i));
		if (temp < a.at(i)) {
			cout << -1 << endl;
			return 0;
		}
		ans += temp;
	}

	cout << ans << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:28:32: error: no matching function for call to 'min(__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type)'
   28 |                 mae.at(i) = min((mae.at(i - 1) - a.at(i - 1)) * 2);
      |                             ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 1 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   template argument deduction/substitution failed:
a.cc:28:32: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   28 |                 mae.at(i) = min((mae.at(i - 1) - a.at(i - 1)) * 2);
      |                             ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   candidate expects 2 arguments, 1 provided
a.cc:37:35: error: no matching function for call to 'min(__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type)'
   37 |                 ushiro.at(i) = min(ushiro.at(i + 1) + a.at(i));
      |                                ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 1 provided
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   template argument deduction/substitution failed:
a.cc:37:35: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   37 |                 ushiro.at(i) = min(ushiro.at(i + 1) + a.at(i));
      |                                ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   candidate expects 2 arguments, 1 provided