Language: C++

#include<bits/stdc++.h>
using namespace std;
const int maxn=15;
const int mod=1e9+7; 
const int S=(1<<4)+10;
int n,k,top=0;
int a[maxn],bel[maxn];
struct cat 
{
	int val,col;
	bool operator ==(const cat &b)const
	{
		return val==b.val&&col==b.col;
	}
	bool operator <(const cat &b)const 
	{
		return val==b.val?col<b.col:val<b.val;
	}
}s[S+maxn];
int L[maxn],R[maxn];
int pl[maxn],pr[maxn];
bool dfs2(int dep,int lim)
{
	if(dep==k+1)
	{
		bool flag=1;
		for(int i=1;i<=lim;i++)
		if(L[i]<=pl[i]&&pr[i]<=R[i])flag=1;
		else return false;
		return true;
	}
	for(int i=1;i<=lim;i++)
	{
		int tmp=L[i],flag=0;
		L[i]=max(L[i],a[dep]),R[i]+=a[dep];
		flag=dfs2(dep+1,lim);
		L[i]=tmp,R[i]-=a[dep];
		if(flag)return true;
	}
	return false;
}
int l[maxn],r[maxn],inv[maxn];
int ans=0;
int Pow(int a,long long k)
{
	int ret=1;
	while(k)
	{
		if(k&1)ret=ret*1LL*a%mod;
		a=a*1LL*a%mod,k>>=1; 
	}
	return ret;
}
int C(int n,int m)
{
	int mul=1,c=1;
	for(int i=n-m+1;i<=n;i++)mul=mul*1LL*i%mod; 
	for(int i=1;i<=m;i++)c=c*1LL*i%mod;
	return mul*1LL*Pow(c,mod-2)%mod;
}
void calc(int cnt)
{
	for(int i=1;i<=cnt;i++)
	{
		if(s[bel[i]-1].col)pl[i]=s[bel[i]-1].val+1;
		else pl[i]=s[bel[i]-1].val;
		if(s[bel[i]].col)pr[i]=s[bel[i]].val;
		else pr[i]=s[bel[i]].val-1;
	}
	if(!dfs2(1,cnt))return;
	int now=0;
	l[++now]=0,r[now]=n;
	l[++now]=pl[1],r[now]=pr[1];
	for(int i=2;i<=cnt;i++)
	{
		l[++now]=1,r[now]=n;
		l[++now]=pl[1],r[now]=pr[1];
	}
	l[++now]=0,r[now]=n;
	int all=(1<<now)-1;
	for(int s=0;s<=all;s++)
	{
		long long sum=0;
		for(int i=1;i<=now;i++)
		if(s&(1<<i-1))sum+=r[i]+1;
		else sum+=l[i];
		if(sum>n)continue;
		ans+=(count(s)&1?-1:1)*C(n-sum+now-1,now-1)%mod;
		ans=(ans%mod+mod)%mod;
	}
}
void dfs(int dep)
{
	calc(dep-1);
	if(dep==k+1)return;
	for(int i=2;i<=top;i++)bel[dep]=i,dfs(dep+1);
}
int main()
{
	scanf("%d%d",&n,&k);
	
	for(int i=1;i<=k;i++)scanf("%d",&a[i]);
	int all=(1<<k)-1;
	for(int i=1;i<=k;i++)s[++top].val=a[i],s[top].col=0;
	for(int s=1;s<=all;s++)
	{
		int sum=0;
		for(int i=1;i<=k;i++)if(s&(1<<i-1))sum+=a[i];
		s[++top].val=sum;
		s[top].col=1;
	}
	sort(s+1,s+1+top);
	top=unique(s+1,s+1+top)-s-1;
	dfs(1);	
	printf("%d\n",ans);
}

Compiler output:
a.cc: In function 'void calc(int)':
a.cc:88:28: error: no matching function for call to 'count(int&)'
   88 |                 ans+=(count(s)&1?-1:1)*C(n-sum+now-1,now-1)%mod;
      |                       ~~~~~^~~
In file included from /usr/include/c++/14/algorithm:61,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algo.h:4025:5: note: candidate: 'template<class _IIter, class _Tp> typename std::iterator_traits< <template-parameter-1-1> >::difference_type std::count(_IIter, _IIter, const _Tp&)'
 4025 |     count(_InputIterator __first, _InputIterator __last, const _Tp& __value)
      |     ^~~~~
/usr/include/c++/14/bits/stl_algo.h:4025:5: note:   candidate expects 3 arguments, 1 provided
In file included from /usr/include/c++/14/algorithm:86:
/usr/include/c++/14/pstl/glue_algorithm_defs.h:101:1: note: candidate: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Tp> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, typename std::iterator_traits<_II>::difference_type> std::count(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, const _Tp&)'
  101 | count(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
      | ^~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:101:1: note:   candidate expects 4 arguments, 1 provided
a.cc: In function 'int main()':
a.cc:109:18: error: invalid types 'int[int]' for array subscript
  109 |                 s[++top].val=sum;
      |                  ^
a.cc:110:18: error: invalid types 'int[int]' for array subscript
  110 |                 s[top].col=1;
      |                  ^