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

Wy WA???????? 1005(C++)
Posted by faust 22 Sep 2002 13:40
#include <iostream.h>
#include <stdlib.h>

void main(void)
{
    int N;

    cin >> N;

    long *w =  new long [N];
    long p1 = 0;
    long p2 = 0;

    int pile = 1;

    for(int i = 0 ; i < N ; ++i)
        cin >> w[i];

    for(i = 0 ; i < N - 1 ; ++i)
    {
        for(int j = i + 1 ; j < N ; ++j)
        {
            if(w[j] > w[i])
            {
                long tmp = w[i];
                w[i] = w[j];
                w[j] = tmp;
            };
        };
    };

    for(i = 0 ; i < N ; ++i)
    {
        if(pile == 1)
        {
            p1 += w[i];

            if(p1 > p2)
                pile = 2;
        }else
        {
            p2 += w[i];

            if(p2 > p1)
                pile = 1;
        };
    };

    cout << abs(p1 - p2);

    delete [] w;
};
I know :(
Posted by faust 22 Sep 2002 14:06