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

Accepted whis wrong answer
Posted by Actics 29 Jun 2011 04:25
See, this is my code. For 4 stone (48 22 27 3) he said: 4. But correct answer is 2!

--------------------------------------------------

#include <stdio.h>
#include <algorithm>
using namespace std;
int main() {
    int n, i, s=0, x, y=0, *m;
    scanf("%d", &n);
    m = new int[n];
    for (i=0; i<n; i++) {
        scanf("%d", &m[i]);
        s += m[i];
    }
    s /= 2;
    sort(m, m+n);
    x = m[n-1];
    for (i=n-2; i>-1; i--)
        if (x+m[i] <= s)
            x += m[i];
        else
            y += m[i];
    printf("%d", (x>y)?(x-y):(y-x));
    return 0;
}

Edited by author 29.06.2011 04:25