Imagine you have elements A, B and C with weights 1, 2 and 3. You compute the sum of the weights, which is 1+2+3 = 6
At this point you add all the elements into a sorted set using this algorithm:
SUM = ELEMENTS.TOTAL_WEIGHT // 6 in this case.
SCORE = 0