Language: C++

#include <bits/stdc++.h>

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef int64_t ll; typedef vector<int> VI; typedef pair<int,int> pii;
typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){cerr<<"\n";} template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	VL a(n+1);
	
	rep(i, n+1) cin >>a[i];
	if(n==0){ puts(a[0]==1? "1":"0"); return 0;}
	if(a[0]>0 && n>0){ puts("-1");return 0;}
	if(a.back()==0){ puts("-1");return 0;}
	const ll INF = 1LL<<61;
	VL mz(n+1), pz(n+1);
	mz[0]=1;
	rep(i, n){
		mz[i+1]=min(INF, (mz[i] - a[i]) * 2LL);
		if(mz[i]<a[i]){ { puts("-1");return 0;}}
	}
	ll cr=0;
	repr(i, n, 0){
		cr += a[i];
		pz[i] = cr;
	}
	//for(auto x :mz) cerr<<x<<" "; dbg();
	//for(auto x :pz) cerr<<x<<" "; dbg();
	ll ans = 0;
	rep(i, n+1){
		if(mz[i] < a[i]){puts("-1");return 0;}
		ans += min(pz[i], mz[i]);
	}
	cout << ans <<"\n";
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:30:28: error: no matching function for call to 'min(const ll&, long long int)'
   30 |                 mz[i+1]=min(INF, (mz[i] - a[i]) * 2LL);
      |                         ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
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:30:28: note:   deduced conflicting types for parameter 'const _Tp' ('long int' and 'long long int')
   30 |                 mz[i+1]=min(INF, (mz[i] - a[i]) * 2LL);
      |                         ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
/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:30:28: note:   mismatched types 'std::initializer_list<_Tp>' and 'long int'
   30 |                 mz[i+1]=min(INF, (mz[i] - a[i]) * 2LL);
      |                         ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~