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 wrong?
Posted by Phoenix264 12 Jan 2012 18:40
#include <stdio.h>
#include <math.h>

int a[20];
int count;

int main()
{

   scanf("%d", &count);

   for(int i = 0; i < count; i++)
   {
        scanf("%d", &a[i]);
   }


    // Сортировка пузырьком
    bool t = true;
    while(t)
    {
        t = false;
        for(int i = 0; i < count-1; i++)
        {
            if(a[i] > a[i+1])
            {
                int tmp = a[i];
                a[i] = a[i+1];
                a[i+1] = tmp;
                t = true;
            }
        }
    }



   int r1 = a[count - 1], r2 = 0;

   for(int i = count - 2; i >= 0; i--)
   {
        if(r1 > r2)
            r2 += a[i];
        else
            r1 += a[i];
   }


   if(r2 > r1)
       r1 = r2 - r1;
   else
       r1 = r1 - r2;

   printf("%d\n", r1);

   return 0;
}