Language: C++

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    int n; cin>>n;
    vector<ll> p(n+1), q(n+1);
    rep(i,n+1) cin>>p[i];
    q[n]=p[n];
    rep(i,n) q[n-i-1]=q[n-i]+p[n-i-1];
    vector<ll> an(n+1);
    an[0]=1;
    if(p[0]==1){
        if(n==0){
            cout<<1<<endl;
            return 0;
        }
        else{
            cout<<-1<<endl;
            return 0;
        }
    }
    else if(p[0]>1){
        cout<<-1<<endl;
        return 0;
    }
    rep(i,n){
        int a=an[i]-p[i];
        if(a<=0){
            if(i<n){
                cout<<-1<<endl;
                return 0;
            }
        }
        else{
            an[i+1]=min(a*2,q[i+1]);
        }
    }
    if(an[n]!=p[n]){
        cout<<-1<<endl;
        return 0;
    }
    ll ans=0;
    rep(i,n+1) ans+=an[i];
    cout<<ans<<endl;
    return 0;
}


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