Dzięki mariusz193, nareszcie ACC. Problem był w tym, że źle rozumiałem funkcję lower_bound().
Myślałem, że wyszukuje ona największą wartość xi wektora [x1,x2,...,xn] taką że xi <= v,
gdzie v - szukana wartość.
Tymczasem z dokumentacji:
"[lower_bound()] Returns an iterator pointing to the first element in the range [first, last) that is not less than (i.e. greater or equal to) value."
Wystarczyło zamienić lower_bound(...) na upper_bound(...)-1.
Czy powinienem usunąć swój kod źródłowy?