Language: C++

/*raghav0307 - Raghav Gupta*/
 
#include <bits/stdc++.h>
using namespace std;
 
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
 
#define ff first
#define ss second
#define pb push_back
#define fast_io() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define int ll

typedef long long ll;
typedef pair<int, int> pii;
typedef long double ld;
 
typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const int MAXN = 1e5 + 5;

int n;
int leaves[MAXN];
int maxNodes[MAXN];

signed main(){
	fast_io();
	
	cin >> n;
	for(int i = 0; i <= n; i++){
		cin >> leaves[i];
	}

	maxNodes[0] = 1;
	for(int i = 1; i <= n; i++){
		maxNodes[i] = min(1e18, maxNodes[i-1]*2);
	}

	int l[n+1];
	l[n] = leaves[n];
	int r[n+1];
	r[n] = leaves[n];

	// cout << "level: " << n << " l: " << l << " r: " << r << "\n";

	for(int i = n-1; i >= 0; i--){
		
		l[i] = leaves[i] + (l[i+1] + 1)/2;
		r[i] = min(r[i+1] + leaves[i], maxNodes[i]);
		
		if(l[i] > r[i]){
			cout << "-1\n";
			return 0;
		}
		// cout << "level: " << i << " l: " << l << " r: " << r << "\n";
	}

	int ans = 1;
	for(int i = 1; i <= n; i++){
		r[i] = min(r[i], 2*(r[i-1] - leaves[i-1]));
		ans += r[i];
		if(l[i] > r[i]){
			cout << "-1\n";
			return 0;
		}
		// cout << "level: " << i << " l: " << l << " r: " << r << "\n";
	}

	cout << ans << "\n";

	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:37:34: error: no matching function for call to 'min(double, ll)'
   37 |                 maxNodes[i] = min(1e18, maxNodes[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:3:
/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:37:34: note:   deduced conflicting types for parameter 'const _Tp' ('double' and 'll' {aka 'long long int'})
   37 |                 maxNodes[i] = min(1e18, maxNodes[i-1]*2);
      |                               ~~~^~~~~~~~~~~~~~~~~~~~~~~
/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:37:34: note:   mismatched types 'std::initializer_list<_Tp>' and 'double'
   37 |                 maxNodes[i] = min(1e18, maxNodes[i-1]*2);
      |                               ~~~^~~~~~~~~~~~~~~~~~~~~~~