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