Consider current pair and find if there is an element in a1 [ ] such that these three form a required triplet
if ( s . find ( sum - a2 [ i ] - a3 [ j ] ) != s . end ( ) ) return true ; } } return false ; }