#include#include #include using namespace std;int n,a[100005],dp[100005],sum,half,ans;int main(){ scanf("%d",&n); for(int i=1;i<=n;i++){ scanf("%d",&a[i]); sum+=a[i]; } half=sum>>1; sort(a+1,a+n+1); for(int i=n;i>=1;i--){ for(int j=sum;j>=0;j--){ if(j>=a[i])dp[j]=max(dp[j],dp[j-a[i]]+a[i]); if(dp[j]>half&&dp[j]-a[i]<=half){ ans=max(ans,dp[j]); } } } printf("%d\n",ans);}