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 my program WA ????why why ??
Posted by dinglinbin 22 Sep 2007 09:15

#include <stdio.h>
#include <algorithm>

using namespace std ;

int main(int argc, char* argv[])
{
        int N ;
        long i ;
        double inta[100001];
        long sum1 , sum2 ;
        while(scanf("%d",&N)!=EOF)
        {
                for( i = 0 ;i < N ; i ++)
                        scanf("%lf",&inta[i] ) ;
                sort(inta , inta + N);
                sum1 = inta[N-1] ;
                sum2 = inta[N-2] ;
                for( i = N-3 ; i>=0 ;i--)
                {
                      if( sum1 >= sum2 )
                      {
                        sum2 += inta[i] ;
                      }
                      else
                        sum1 += inta[i] ;
                }
                printf("%ld\n",abs(sum1-sum2) );
        }
        return 0;
}
//---------------------------------------------------------------------------
Re: Why my program WA ????why why ??
Posted by Lomir 22 Sep 2007 10:56
Cause your solution is wrong.
5
3
3
2
2
2

answer 0