Search if a pair can be formed with arr [ i ] .
int rem = sum - arr [ i ] ; if ( m . find ( rem ) != m . end ( ) ) { int count = m [ rem ] ; for ( int j = 0 ; j < count ; j ++ ) cout << " ( " << rem << " , ▁ " << arr [ i ] << " ) " << endl ; } m [ arr [ i ] ] ++ ; } }