浙大acm2059,我用贪心算法但是老wa,哪为高手能帮我解决
//http://acm.zju.edu.cn/show_problem.php?pid=2059
#include<stdio.h>
#include<math.h>
#define N 200
int main()
{
int i,j,k,t,w[N];
char n;
//如果使用unsigned int类型,就WA
while(scanf("%d",&n),n!=-1)
{
int s1=0,s2=0;
for(i=0,k=(n>>1);i<k;i++)
{scanf("%d",&w[i]);s1+=w[i];}
for(;i<n;i++)
{scanf("%d",&w[i]);s2+=w[i];}
if(((s1+s2)&1)) {printf("Sorry\n");continue;}
bool s;
while(1)
{
s=true;
for(i=0;i<k;i++)
for(j=k;j<n;j++)
{
if(fabs((s1-w[i]+w[j])-(s2+w[i]-w[j]))<fabs(s1-s2))
{
s=false;
s1=s1-w[i]+w[j];
s2=s2+w[i]-w[j];
t=w[i];w[i]=w[j];w[j]=t;
}//if
}
if(s)
{
//if(s1>s2)
//{t=s1;s1=s2;s2=t;}
//printf("%d %d\n",s1,s2);
if(s1==s2) printf("%d\n",s1);
else printf("Sorry\n");
break;
}
}//while
}//while
return 1;
}