Language: C++

# include <bits/stdc++.h>
typedef long long lint;
using namespace std;

lint gcd(lint x, lint y) {
  if(x == 0) { return y; }
  else { return gcd(y%x,x); }
}

lint lcm(lint x, lint y) { return x/gcd(x,y)*y; }

lint C(lint n, lint k) {
  if(n == k) { return 1; }
  else if(n < k) { return 0; }
  else if(k == 0) { return 1; }
  else if(k == 1) { return n; }
  else return C(n-1,k-1) + C(n-1,k);
}

lint P(lint n, lint k) {
  if(k == 1) { return n; }
  return (n*(P(n-1,k-1)%1000000007)%1000000007);
}


int main() {
  lint n; cin >> n;
  vector<lint> a(n+1); for(lint i=0;i<=n;i++) { cin >> a[i]; }

  vector<lint> b(n+1), c(n+1);
  b[n] = a[n];
  c[0] = 1LL;

  for(lint i=n-1;i>=0;i--) { b[i] = b[i+1]+a[i]; } // b
  for(lint i=1;i<=n;i++) { c[i] = min((c[i-1]-a[i-1])*2,1000000000000000); } // max leaf

  lint ans=0LL;
  for(lint i=0;i<=n;i++) {
    if(a[i] > c[i]) {
      cout << "-1\n";
      return 0;
    }

    ans += min(lint(b[i]),lint(c[i]));
  } // ans

  cout << ans << endl;
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:35:38: error: no matching function for call to 'min(__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type, long int)'
   35 |   for(lint i=1;i<=n;i++) { c[i] = min((c[i-1]-a[i-1])*2,1000000000000000); } // max leaf
      |                                   ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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:35:38: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'long int')
   35 |   for(lint i=1;i<=n;i++) { c[i] = min((c[i-1]-a[i-1])*2,1000000000000000); } // max leaf
      |                                   ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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:35:38: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   35 |   for(lint i=1;i<=n;i++) { c[i] = min((c[i-1]-a[i-1])*2,1000000000000000); } // max leaf
      |                                   ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~