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 WA#5?
Posted by ScaV 29 Aug 2011 17:56
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int cmp(const void *a, const void *b);

int main()
{
    long num,i;
    double k=0,*ms;
    scanf("%ld",&num);
    ms = (double*)malloc(num*sizeof(double));
    for(i=0; i<num; i++)
        scanf("%lf",&ms[i]);
    qsort(ms,num,sizeof(double),cmp);
    for(i=0; i<num; i++){
        k -= ms[i];
        if(k<0)
            k=-k;
    }
    printf("%.0lf",k);
    return 0;
}
int cmp(const void *a, const void *b)
{
    return -(*(double*)a-*(double*)b);
}

Edited by author 29.08.2011 22:27