fork download
  1. #include <vector>
  2. #include <algorithm>
  3. #include <iostream>
  4.  
  5. int main(){
  6. int t[] = { 15, 25 };
  7. int c[] = { 10, 20, 30 };
  8.  
  9. std::vector<int> tt(t, t + 2);
  10. std::vector<int> cc(c, c + 3);
  11.  
  12. auto lower = std::lower_bound(cc.begin(), cc.end(), tt.front(), [](int a, int b){ return a < b; });
  13. auto upper = std::lower_bound(cc.rbegin(), cc.rend(), tt.back(), [](int a, int b){ return a > b; });
  14.  
  15. size_t beforeCount = lower - cc.begin();
  16. size_t afterCount = upper - cc.rbegin();
  17.  
  18. std::cout << beforeCount << ' ' << afterCount << '\n';
  19. std::cout << *lower << ' ' << *upper << '\n';
  20. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
1 1
20 20