The function upper_bound is used to find the last position that an element may be inserted without changing the order.
template<class ForwardIterator, class T> ForwardIterator upper_bound (ForwardIterator first, ForwardIterator last, const T& value); template<class ForwardIterator, class T, class Compare> ForwardIterator upper_bound (ForwardIterator first, ForwardIterator last, const T& value, Compare comp);
The position where the element can be inserted is returned.