int cmp(const void* a, const void* b){ return *(int*)b - *(int*)a; } int lastStoneWeight(int* stones, int stonesSize){ int i=0,val=stones[0]; while(i<stonesSize-1) { i++; qsort(stones,stonesSize,sizeof(int),cmp); stones[0]-=stones[1]; stones[1]=0; } return stones[0]; }