For upper median traverse the set pr from right
sums = 0 ; for ( int index = pr . size ( ) - 1 ; index >= 0 ; index -- ) { int element = pr . get ( index ) . first ; double weight = pr . get ( index ) . second ;