1 var f:array[0..100005] of boolean; 2 a:array[0..310] of longint; 3 i,n,s,j,ans:longint; 4 5 procedure sort(l,r: longint); 6 var i,j,x,y: longint; 7 begin 8 i:=l; 9 j:=r; 10 x:=a[(l+r) div 2]; 11 repeat 12 while (a[i]<x) do inc(i); 13 while (x<a[j]) do dec(j); 14 if not(i>j) then 15 begin 16 y:=a[i]; a[i]:=a[j]; a[j]:=y; 17 inc(i); 18 j:=j-1; 19 end; 20 until i>j; 21 if l<j then sort(l,j); 22 if i<r then sort(i,r); 23 end; 24 25 begin 26 readln(n); 27 for i:=1 to n do 28 begin 29 read(a[i]); 30 s:=s+a[i]; 31 end; 32 sort(1,n); 33 f[0]:=true; 34 for i:=n downto 1 do 35 for j:=s-a[i] downto 0 do 36 if f[j] then 37 begin 38 f[j+a[i]]:=true; 39 if (j<=s div 2) and (j+a[i]>s div 2) then 40 if ans<j+a[i] then ans:=j+a[i]; 41 end; 42 writeln(ans); 43 end.