Language: C++

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <ctime>
#define N 2005
using namespace std;
int n;
int num[N] , dp[2][N] , q[2][N] , vis[2][N];
template < typename T >
inline void read( T & res ) {
	res = 0;
	char aa = getchar();
	T pd = 1;
	while ( aa < '0' || aa > '9' ) {
		if ( aa == '-' ) {
			pd = -pd;
		}
		aa = getchar();
	}
	while ( aa >= '0' && aa <= '9' ) {
		res = ( res << 1 ) + ( res << 3 ) + ( aa - '0' );
		aa = getchar();
	}
	res *= pd;
	return;
}
inline int abs( int x ) {
	return x < 0 ? -x : x;
}

int main (
	read(n);
	int sum = 0;
	for ( int i = 1 ; i <= n ; ++i ) {
		read(num[i]);
		sum += num[i];
	}
	if ( n == 1 ) {
		printf("%d",sum);
		return 0;
	}
	int pos = 1;
	int head1 , tail1 , tail2;
	tail2 = 0;
	head1 = 1;
	tail1 = 0;
	q[pos][++tail1] = 0;
	for ( int i = 1 ; i <= n ; ++i ) {
		memset( dp[pos] , 0 , sizeof(dp[pos]) );
		memset( vis[pos] , 0 , sizeof(vis[pos]) );
		while ( head1 <= tail1 ) {
			int tem = q[pos][head1];
			head1++;
			if ( num[i] + tem < 2001 ) {	
				if ( !vis[pos ^ 1][num[i] + tem] ) {
					q[pos ^ 1][++tail2] = num[i] + tem;
					dp[pos ^ 1][num[i] + tem] = 1;
					vis[pos ^ 1][num[i] + tem] = 1;
				}
			}
			if ( !vis[pos ^ 1][abs( num[i] - tem )] ) {
				q[pos ^ 1][++tail2] = abs( num[i] - tem );
				dp[pos ^ 1][abs( num[i] - tem )] = 1;
				vis[pos ^ 1][abs( num[i] - tem )] = 1;
			}
		}
		head1 = 1;
		tail1 = tail2;
		tail2 = 0;
		pos ^= 1;
	}
	int res;
	for ( int i = 0 ; i <= 2000 ; ++i ) {
		if ( dp[pos][i] ) {
			res = i;
			break;
		}
	}
	sum = ( sum + res ) >> 1;
	printf("%d",sum);
	return 0;
}

Compiler output:
a.cc:32:5: error: cannot declare '::main' to be a global variable
   32 | int main (
      |     ^~~~
a.cc:33:16: error: expected ')' before ';' token
   33 |         read(n);
      |                ^
      |                )
a.cc:32:10: note: to match this '('
   32 | int main (
      |          ^
a.cc:35:9: error: expected unqualified-id before 'for'
   35 |         for ( int i = 1 ; i <= n ; ++i ) {
      |         ^~~
a.cc:35:27: error: 'i' does not name a type
   35 |         for ( int i = 1 ; i <= n ; ++i ) {
      |                           ^
a.cc:35:36: error: expected unqualified-id before '++' token
   35 |         for ( int i = 1 ; i <= n ; ++i ) {
      |                                    ^~
a.cc:39:9: error: expected unqualified-id before 'if'
   39 |         if ( n == 1 ) {
      |         ^~
a.cc:45:9: error: 'tail2' does not name a type
   45 |         tail2 = 0;
      |         ^~~~~
a.cc:46:9: error: 'head1' does not name a type
   46 |         head1 = 1;
      |         ^~~~~
a.cc:47:9: error: 'tail1' does not name a type
   47 |         tail1 = 0;
      |         ^~~~~
a.cc:48:9: error: 'q' does not name a type
   48 |         q[pos][++tail1] = 0;
      |         ^
a.cc:49:9: error: expected unqualified-id before 'for'
   49 |         for ( int i = 1 ; i <= n ; ++i ) {
      |         ^~~
a.cc:49:27: error: 'i' does not name a type
   49 |         for ( int i = 1 ; i <= n ; ++i ) {
      |                           ^
a.cc:49:36: error: expected unqualified-id before '++' token
   49 |         for ( int i = 1 ; i <= n ; ++i ) {
      |                                    ^~
a.cc:74:9: error: expected unqualified-id before 'for'
   74 |         for ( int i = 0 ; i <= 2000 ; ++i ) {
      |         ^~~
a.cc:74:27: error: 'i' does not name a type
   74 |         for ( int i = 0 ; i <= 2000 ; ++i ) {
      |                           ^
a.cc:74:39: error: expected unqualified-id before '++' token
   74 |         for ( int i = 0 ; i <= 2000 ; ++i ) {
      |                                       ^~
a.cc:80:9: error: 'sum' does not name a type
   80 |         sum = ( sum + res ) >> 1;
      |         ^~~
a.cc:81:15: error: expected constructor, destructor, or type conversion before '(' token
   81 |         printf("%d",sum);
      |               ^
a.cc:82:9: error: expected unqualified-id before 'return'
   82 |         return 0;
      |         ^~~~~~
a.cc:83:1: error: expected declaration before '}' token
   83 | }
      | ^