Language: C++

#include<bits/stdc++.h>
#define rep(i,j,k) for(int i=j;i<=k;i++)
#define rep2(i,j,k) for(int i=j;i>=k;i--)
using namespace std;
template<typename T> void read(T &num){
	char c=getchar();T f=1;num=0;
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){num=(num<<3)+(num<<1)+(c^48);c=getchar();}
	num*=f;
}
template<typename T> void qwq(T x){
	if(x>9)qwq(x/10);
	putchar(x%10+'0');
}
template<typename T> void write(T x){
	if(x<0){x=-x;putchar('-');}
	qwq(x);putchar('\n');
}
long long co[100010];long long mx[100010];

int main(){
	int n;read(n);
	rep(i,0,n)read(co[i]);
	
	if(n==0){write((co[0]==1)?1:-1);}
	else{
		if(co[0]){write(-1);return 0;}
		mx[0]=1;
		rep(i,1,n-1){
			mx[i]=mx[i-1]*2-co[i];mx[i]=min(mx[i],400000000000000000);
			if(mx[i]<1){write(-1);return 0;}
		}
		
		long long now=co[n];long long ans=co[n];
		rep2(i,n-1,0){
			if(now>mx[i]*2){write(-1);return 0;}
			now=min(now,mx[i]);now+=co[i];ans+=now;	
		}
		write(ans);
	}
	return 0;
}

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