Language: C++

#include<iostream>
#include<vector>
#include<set>
#include<algorithm>
#include<map>
#include <bits/stdc++.h>
typedef long long ll;
#define N 100010
using namespace std;

int solve()
{
	ll n;
	ll add;
	cin>>n;
	int ans;
	for (int i=0;i<=n;i++) 
	{
		cin>>a[i];
		add+=a[i];
	}
	for (int i=0;i<=n;i++)
	{
		int now=min(1<<i,add);
		if (i==0&&a[i]==1)
		{
			if (n!=0)
				return -1;
			else
				return 1;
		}
		now-=a[i];
		add-=a[i];
		if (now<0)
			return -1;
		ans+=now; 
	}
	if (now>0)
		return -1;
	return ans;
}

int main() 
{
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
//	int t;
//	cin>>t;
//	while (t--) 
		cout<<solve()<<endl;
	return 0;
}

Compiler output:
a.cc: In function 'int solve()':
a.cc:19:22: error: 'a' was not declared in this scope
   19 |                 cin>>a[i];
      |                      ^
a.cc:24:28: error: no matching function for call to 'min(int, ll&)'
   24 |                 int now=min(1<<i,add);
      |                         ~~~^~~~~~~~~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 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:24:28: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   24 |                 int now=min(1<<i,add);
      |                         ~~~^~~~~~~~~~
/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,
                 from a.cc:4:
/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:24:28: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   24 |                 int now=min(1<<i,add);
      |                         ~~~^~~~~~~~~~
a.cc:25:27: error: 'a' was not declared in this scope
   25 |                 if (i==0&&a[i]==1)
      |                           ^
a.cc:32:22: error: 'a' was not declared in this scope
   32 |                 now-=a[i];
      |                      ^
a.cc:38:13: error: 'now' was not declared in this scope; did you mean 'pow'?
   38 |         if (now>0)
      |             ^~~
      |             pow