Language: C++

#include <cstdio>
#include <algorithm>

using namespace std;

#define INF 100000000005

int N;
int A[100005];
long long ans = 1;
long long usable[100005], mval[100005], aft[100005];

int main() {
    scanf("%d", &N);
    for (int i = 0; i <= N; i++) scanf("%d", &A[i]);
    if (A[0] != 1) usable[0] = 1;
    mval[0] = 1;
    for (int i = 1; i <= N; i++) {
        int add = min(INF, usable[i - 1] * 2);
        mval[i] = add;
        ans += add;
        usable[i] = add - A[i];
        if (usable[i] < 0) {
            printf("-1\n");
            return 0;
        }
    }
    if (mval[N] > A[N]) {
        ans -= mval[N] - A[N];
        mval[N] = A[N];
    }
    //aft[N] = A[N];
    //ans += A[N];
    for (int i = N - 1; i >= 1; i--) {
        if ((mval[i + 1] + 1) / 2 + A[i] > mval[i]) {
            printf("-1\n");
            return 0;
        }
        if (mval[i] - mval[i + 1] > A[i]) {
            ans -= mval[i] - mval[i + 1] - A[i];
            mval[i] = A[i] + mval[i + 1];
        }
        /*
        aft[i] = min(aft[i + 1] + A[i], 1 << i);
        ans += aft[i];
        */
    }
    printf("%lld\n", ans);
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:19:22: error: no matching function for call to 'min(long int, long long int)'
   19 |         int add = min(INF, usable[i - 1] * 2);
      |                   ~~~^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from a.cc:2:
/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:19:22: note:   deduced conflicting types for parameter 'const _Tp' ('long int' and 'long long int')
   19 |         int add = min(INF, usable[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:19:22: note:   mismatched types 'std::initializer_list<_Tp>' and 'long int'
   19 |         int add = min(INF, usable[i - 1] * 2);
      |                   ~~~^~~~~~~~~~~~~~~~~~~~~~~~