Language: C++

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



int main() {

    int N;
    int A[100001];
    cin >> N;
    for (int i = 0; i < N + 1; i++) cin >> A[i];
    //今の深さの点の数
    long long now = 1;
    //int mae = 0;
    long long ans = 0;
    //末端の数
    long long sum = 0;
    //分岐した回数
    long long route = 1;
    
    for (int i = 0; i < N + 1; i++)
    {
        sum += A[i];
    }
    int s = sum;
    //cout << sum << endl;
    for (int i = 0; i < N + 1; i++)
    {
        /*
        //cout << now <<route<< endl;
        ans += now;
        //cout << now<< " ";
        now -= A[i];
        sum -= A[i];
        now = min(now * 2, sum);

        //cout << now << endl;
        if (i != N && now <= 0)
        {
            cout << -1 << endl;
            return 0;
        }
        else if (i == N && now != 0)
        {
            cout << -1 << endl;
            return 0;
        }*/

        
        ans += now;
        now -= A[i];
        s -= A[i];
        //できるだけ早く分岐しておく
        long long a = now;
        /*
        //now 2倍ルート
        if (route + a < sum)
        {
            //新しい分岐はa個
            now += a;
            route += a;
        }
        //nowがそれ以降の和になるルート
        else
        {
            //基本的にrouteは1+枝の数
            //ある瞬間のroute-1がそれまでの葉の数と等しければいい
            //分岐した数だけ葉が増える、route+=nはA[i]=nを意味する
            //つまりrouteはそれまでのA[i]の和、route= sum-sumA[i]
            //now-A[i]（分岐＝葉の数）=葉以外の数、
            //葉の枚数＋全部の和-分岐の数（）

            //now=sum-sumA[i-1]なら、

            //新しい分岐はsum-route個
            //（最終的な道の数）ー（今の道の数）をnow（今の道の数）に足して（最終的な道の数）にする
            //now += sum - route;
            now = s;
            route += sum - route;
        }*/
        now = min(a * 2, s);

        if (i != N && now <= 0)
        {
            cout << -1 << endl;
            return 0;
        }
        else if (i == N && now != 0)
        {
            cout << -1 << endl;
            return 0;
        }


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

Compiler output:
a.cc: In function 'int main()':
a.cc:81:18: error: no matching function for call to 'min(long long int, int&)'
   81 |         now = min(a * 2, s);
      |               ~~~^~~~~~~~~~
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:81:18: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   81 |         now = min(a * 2, s);
      |               ~~~^~~~~~~~~~
/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:81:18: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   81 |         now = min(a * 2, s);
      |               ~~~^~~~~~~~~~