|
|
back to boardWhy I've got WA#1 #include<stdio.h> int main() { long x[20],ans=0; int i=0,n=0; int j=0; long tmp=0,p[2]; scanf("%ld",&n); for(i=0;i<n;i++) scanf("%ld",&x[i]); for(i=0;i<n;i++) { for(j=i+1;j<n;j++) if(x[j-1]<x[j]) { tmp=x[j]; x[j]=x[j-1]; x[j-1]=tmp; } } for(i=0;i<n;i++) { if(i<2) p[i]=x[i]; else if(p[0]>p[1]) p[1]+=x[i]; else p[0]+=x[i]; } ans=p[1]-p[0]; if(ans<0) ans=-ans; printf("%ld\n",ans); } My code worked all of my test cases. Try this test: 5 6 6 6 9 9 correct answer is 0 |
|
|