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

whats wrong in this solution question number 1005
Posted by Akshay R. Murarka 22 Dec 2011 18:17
#include <stdio.h>
int main()
{
    int number;
    int b;
        int weight;
        int sum;
        int sum1;
        int i;
        int k;
        int p;
    int a[20];
    status:
        scanf("%d", &number);
        if(number>=1&&number<=20)
        {
            for(weight=0;weight<number;weight++)
            {
                scanf ("%d", &b);
                if(b>=1&&b<=100000)
                a[weight]=b;
                else
                weight--;
            }
            for(i=0;i<number;i++)
             {
             for(weight=0;weight<number;weight++)
            {
               if(a[weight]>a[weight+1])
             {
                    p=a[weight];
                 a[weight]=a[weight+1];
                   a[weight+1]=p;
            }
            }
        }
          sum=a[number-1];
        sum1=a[number-2]+a[number-3];
        for(i=4;i<=number;i++)
         {
             if((sum1+a[number-i])<=sum)
             sum1=sum1+a[number-i];
            else
            sum=sum+a[number-i];
        }
        k=sum-sum1;
        printf ("%d\n", k);
}
        else
        {
            printf("enter again\n");
            goto
            status;
        }
       return 0;
}

Edited by author 22.12.2011 18:18