Store values according to the mentioned approach
for ( int i = 0 ; i < N ; ++ i ) { if ( v [ i ] . first >= 0 ) { pos . add ( new pair ( - v [ i ] . second , v [ i ] . first ) ) ; } else { neg . add ( new pair ( v [ i ] . first - v [ i ] . second , - v [ i ] . first ) ) ; } }