ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1005. Stone Pile

Why I've got WA#1
Posted by pitchayah 27 Jul 2007 00:09
#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:
Posted by Victor Barinov (TNU) 27 Jul 2007 12:34
5
6
6
6
9
9

correct answer is 0