Language: C++

#include<bits/stdc++.h>
using namespace std;
 
typedef unsigned int ui;
#define rep(i,l,r) for(int i=l;i<=r;++i)
const int N=2000+5,A=4e6+5;
int cnt[A];
ui a[1<<17];int mx;
bool Count(int x)
{
	return a[x/32]&(1<<(x&31));
}
void move(int x)
{
	int u=mx/32;mx+=x;
	int du=x/32,di=x&31;
	if(!di)
	{
		for(int i=u;i>=0;--i)a[i+du]|=a[i];
		return ;
	}
	for(int i=u;i>=0;--i)
	{
		a[i+du+1]|=a[i]>>32-di;
		a[i+du]|=a[i]<<di;
	}
}
 
int main()
{
	//freopen("will.in","r",stdin);freopen("will.out","w",stdout);
	int n;
	cin>>n;
	int sum=0;
	rep(i,1,n)
	{
		int x;
		scanf("%d",&x);
		sum+=x;
		++cnt[x];
	}
	mx=0;a[0]=1;
	rep(i,1,sum)
	{
		while(cnt[i]>2){++cnt[i*2];cnt[i]-=2;}
		while(cnt[i]--)move(i);
	}
	int tot=0;
	rep(i,1,sum)
	if(Count(i))++tot;
	tot=(tot+1)/2;
	rep(i,1,sum)
	if(Count(i))
	{
		if(!--tot)
		{
			cout<<i;
			exit(0);
		}
	}
}
#include<bits/stdc++.h>
using namespace std;

typedef unsigned int ui;
#define rep(i,l,r) for(int i=l;i<=r;++i)
const int N=2000+5,A=4e6+5;
int cnt[A];
ui a[1<<17];int mx;
bool Count(int x)
{
	return a[x/32]&(1<<(x&31));
}
void move(int x)
{
	int u=mx/32;mx+=x;
	int du=x/32,di=x&31;
	if(!di)
	{
		for(int i=u;i>=0;--i)a[i+du]|=a[i];
		return ;
	}
	for(int i=u;i>=0;--i)
	{
		a[i+du+1]|=a[i]>>32-di;
		a[i+du]|=a[i]<<di;
	}
}

int main()
{
	//freopen("will.in","r",stdin);freopen("will.out","w",stdout);
	int n;
	cin>>n;
mx=0;a[0]=1;
	rep(i,1,n)
	{
		int x;
		scanf("%d",&x);
		move(x);
	}
	
	int tot=0;
	rep(i,1,mx)
	if(Count(i))++tot;
	tot=(tot+1)/2;
	rep(i,1,mx)
	if(Count(i))
	{
		if(!--tot)
		{
			cout<<i;
			exit(0);
		}
	}
}


Compiler output:
a.cc:67:11: error: redefinition of 'const int N'
   67 | const int N=2000+5,A=4e6+5;
      |           ^
a.cc:6:11: note: 'const int N' previously defined here
    6 | const int N=2000+5,A=4e6+5;
      |           ^
a.cc:67:20: error: redefinition of 'const int A'
   67 | const int N=2000+5,A=4e6+5;
      |                    ^
a.cc:6:20: note: 'const int A' previously defined here
    6 | const int N=2000+5,A=4e6+5;
      |                    ^
a.cc:68:5: error: redefinition of 'int cnt [4000005]'
   68 | int cnt[A];
      |     ^~~
a.cc:7:5: note: 'int cnt [4000005]' previously declared here
    7 | int cnt[A];
      |     ^~~
a.cc:69:4: error: redefinition of 'ui a [131072]'
   69 | ui a[1<<17];int mx;
      |    ^
a.cc:8:4: note: 'ui a [131072]' previously declared here
    8 | ui a[1<<17];int mx;
      |    ^
a.cc:69:17: error: redefinition of 'int mx'
   69 | ui a[1<<17];int mx;
      |                 ^~
a.cc:8:17: note: 'int mx' previously declared here
    8 | ui a[1<<17];int mx;
      |                 ^~
a.cc:70:6: error: redefinition of 'bool Count(int)'
   70 | bool Count(int x)
      |      ^~~~~
a.cc:9:6: note: 'bool Count(int)' previously defined here
    9 | bool Count(int x)
      |      ^~~~~
a.cc:74:6: error: redefinition of 'void move(int)'
   74 | void move(int x)
      |      ^~~~
a.cc:13:6: note: 'void move(int)' previously defined here
   13 | void move(int x)
      |      ^~~~
a.cc:90:5: error: redefinition of 'int main()'
   90 | int main()
      |     ^~~~
a.cc:29:5: note: 'int main()' previously defined here
   29 | int main()
      |     ^~~~