Language: C++

#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000000000000

int N;
vector<long long> A;
bool f = true;
long long ans = 0;

long long dfs(int depth,long long x){
	if(depth==N){
		if(x<A[depth])f=false;
		ans += A[depth];
		return A[depth];
	}
	long long maxi;
	if(depth==0) maxi = 1;
	else maxi = min(Inf,x*2 - A[depth]);
	
	x-=A[depth];
	
	long long ret = dfs(depth+1,min(x*2,Inf));
	if(ret>x){
		if((ret+1)/2>x){
			f=false;
			return 0LL;
		}
		else{
			ret = x;
		}
	}
	if(ret<0)f=false;
	ret += A[depth];
	ans += ret;
	return ret;
}

int main(){
	
	cin>>N;
	
	for(int i=0;i<=N;i++){
		long long t;
		cin>>t;
		A.push_back(t);
	}
	
	dfs(0,1);
	
	if(f)cout<<ans<<endl;
	else cout<<-1<<endl;
	
	return 0;
}

Compiler output:
a.cc: In function 'long long int dfs(int, long long int)':
a.cc:20:24: error: no matching function for call to 'min(long int, long long int)'
   20 |         else maxi = min(Inf,x*2 - A[depth]);
      |                     ~~~^~~~~~~~~~~~~~~~~~~~
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:   template argument deduction/substitution failed:
a.cc:20:24: note:   deduced conflicting types for parameter 'const _Tp' ('long int' and 'long long int')
   20 |         else maxi = min(Inf,x*2 - A[depth]);
      |                     ~~~^~~~~~~~~~~~~~~~~~~~
/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, 2 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:   candidate expects 1 argument, 2 provided
/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:   template argument deduction/substitution failed:
a.cc:20:24: note:   mismatched types 'std::initializer_list<_Tp>' and 'long int'
   20 |         else maxi = min(Inf,x*2 - A[depth]);
      |                     ~~~^~~~~~~~~~~~~~~~~~~~
a.cc:24:40: error: no matching function for call to 'min(long long int, long int)'
   24 |         long long ret = dfs(depth+1,min(x*2,Inf));
      |                                     ~~~^~~~~~~~~
/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:   template argument deduction/substitution failed:
a.cc:24:40: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'long int')
   24 |         long long ret = dfs(depth+1,min(x*2,Inf));
      |                                     ~~~^~~~~~~~~
/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, 2 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:   candidate expects 1 argument, 2 provided
/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:   template argument deduction/substitution failed:
a.cc:24:40: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   24 |         long long ret = dfs(depth+1,min(x*2,Inf));
      |                                     ~~~^~~~~~~~~