Writing your own sort or binary search in a timed test wastes minutes and invites bugs. <algorithm> and <numeric> give tested versions like sort, lower_bound, reverse and accumulate that work on any range. Reach for them first in any C++ solution. Remember that lower_bound and binary_search only give correct answers on a sorted range.