Smart Phone.

I was trying this problem of ZCO Practice Contest and have a solution to it here.Can anyone find any bug in this because i am getting WA?

Your compare function is incorrectly written. It will work for integers but not for long long. Hence, rewrite it to something like,

int cmpfunc (const void * a, const void * b){
    if( * (long long int * )a - * (long long int * )b < 0 )
        return -1;
    if( * (long long int * )a - * (long long int * )b > 0 )
        return 1;
    if( * (long long int * )a - *(long long int * )b == 0 )
        return 0;

Check it out here if you’re still having any problem with the comparator code.

Hope it works! :slight_smile:

1 Like

logic is not correct because it does not solve even first case of problem itself …
according to your logic it should be 53 because after sorting this would be the last element in the sorted array … i am trying this problem but i am getting the TLE… if i would be able to solve the problem … i will tell you soon… thanks. Hope this helps… If not please tell where i lag.

There’s some problem in formatting, I’ll fix it soon. The asterisks aren’t visible somehow.
I’ve given you the link if it still doesn’t work, you may check it out.