write an algorithm for which
the input is n pairs on whole positive numbers:
(x1,w1),..,(xn,wn)

and number k.

the output is the k smallest in a list
where xi appears wi times

for example: n=4
k=8
(1,3),(7,2),(5,4),(3,2)
gives us
the list
1,1,1,7,7,5,5,5,5,3,3
and the out put is 5 (becuase the 8'th smallest cell is 8)

the solution makes three arrays:
one for the x coordinates X
one for the w coordinates W

and the third is XW=[(x1,w1),..,(xn,wn)]


cant understand what are they doing in this code to get the k'th smallest?
http://i40.tinypic.com/54f67p.png