第2059:
#include < vcl.h>
#include < stdio.h>
#include < stdlib.h>
#include < string.h>
int N , inta[101], Max[2][2001] ;
int main()
{
int i , j, k , p , sum ;
while(scanf("%d", &N)!=EOF)
{
if(N < 0
)
return 0 ;
for(i =0 ; i< N ;i++)
scanf("%d",&inta[i] ) ;
memset(Max ,-1 ,sizeof(Max) );
Max[1][0] = 0 ;
p = 0 ;
sum =0 ;
for( i = 0 ; i < N ; i++ , p = 1- p
)
{
memcpy(Max[p] , Max[1-p] , sizeof(Max[p]) ) ;
sum += inta[i] ;
for( j =0 ; j<= sum ; j++)
{
k = abs(j + inta[i]) ;
if(
k <=sum && Max[p][k] < Max[1-p][j] + inta[i] && Max[1-p][j] >= 0 )
Max[p][k] = Max[1-p][j] + inta[i] ;
k = abs(j - inta[i]);
if(
k <=sum && Max[p][k] < Max[1-p][j] + inta[i] && Max[1-p][j] >= 0 )Max[p][k] = Max[1-p][j] + inta[i];
}
}
if( Max[1-p][0] )printf("%d\n",Max[1-p][0] / 2 ) ;
else printf("Sorry\n");
}
return 0 ;
}