SPOJ JOHNNY

find the sum half it and then sort the array and accordingly store the positions and then find the sum of the sorted array which is nearest to half the sum of weights.