I have a vector of integer scores = 10, 23, 29, 77, 8, 43, 56, 3, a number predict = 42, and a start index = 2 as well as a number predict = 42.
I'm looking for two values that are (greater than and less than) 42 in the range of start index = 2 and finish index = 7.
scores = 10, 23, 29, 77, 8, 43, 56, 3 (search only inside i=2 to i=7)
As a result, 29 is little less than predict=42.
Also, 43 is a touch higher than the forecasted 42.
How did I come up with these figures?
Sample Code:
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
    vector<int> scores = {10, 23, 29, 77, 8, 43, 56, 3}; //Unsorted
    int predict = 42;
    int startFromIndex = 2;
    
    int littleLessThanPredict; // = 29
    int littleMoreThanPredict; // = 43
    
    //lower_bound
    //upper_bound
    
    return 0;
}
In consideration of this scenario,
On an unsorted range, how do I utilise the std::lower bound and std::upper bound functions?
How can I temporarily sort a portion of a vector and apply my own function?
Is there a method to get the desired result by combining the std::min element and std::lower bound functions?