# 愚公的遗愿

``````3
1 2 3``````

``3 3``

``````#include<stdio.h>
#include<string.h>

#define LL long long
#define max(a,b) a>b? a:b

int num[1010];
int f[50000];

int main()
{
int n;
while(scanf("%d",&n)==1)
{
int sum=0;

for(int i=0;i<n;i++){
scanf("%d",&num[i]);
sum+=num[i];
}
memset(f,0,sizeof(f));

int s=sum/2;

for(int i=0;i<n;i++)
for(int j=s;j>=num[i];j--)
f[j]=max(f[j],f[j-num[i]]+num[i]);
printf("%d %d\n",f[s],sum-f[s]);

}

return 0;
}
``````

``````#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cmath>
using namespace std;
int a[1005];
int n;
int main()
{
while(~scanf("%d",&n))
{
int sum=0,mins;
for(int i=0;i<n;i++)
{
scanf("%d",&a[i]);
sum+=a[i];
}
mins=sum;
sort(a,a+n);
int t=0,k=0,n1,n2;
for(int i=0;i<n;i++)
if(t<sum/2)
{
t+=a[i];
k++;
}
else break;
if(sum%2==0&&t==sum/2)
printf("%d %d\n",t,t);
else
{
int temp=sum-t;
n1=temp;
n2=t;
mins=fabs(t-temp);
for(int j=0;j<k;j++)
{
int x=temp+a[j];
int y=t-a[j];
if(fabs(x-y)<mins)
{
mins=fabs(x-y);
n1=x;n2=y;
}
}
if(n1>n2)
printf("%d %d\n",n2,n1);
else printf("%d %d\n",n1,n2);
}
}

return 0;
} ``````