a vector that store indices of the negative elements
vector < int > neg ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] > 0 ) pos . push_back ( i ) ; else if ( arr [ i ] < 0 ) neg . push_back ( i ) ; }