use inplace_merge instead of sort