fork(3) download
  1. #include <algorithm>
  2. #include <vector>
  3. #include <iostream>
  4.  
  5. int main() {
  6. std::vector<std::pair<int,int> > v = {{1,0},{0,1},{3,2},{6,3},{2,4},{4,5},{7,6},{5,7}};
  7. const int l = 2;
  8. const int r = 5;
  9.  
  10. auto begin = v.begin() + l;
  11. auto end = v.begin() + r + 1;
  12. auto max_value = *std::max_element(begin, end);
  13. v.erase(std::remove_if(begin, end, [&](const auto& p) {return p.first != max_value.first; }), end);
  14.  
  15. std::cout << "[";
  16. for (auto& p : v) {
  17. std::cout << "(" << p.first << ", " << p.second << ")";
  18. }
  19. std::cout << "]\n";
  20. }
  21.  
Success #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
[(1, 0)(0, 1)(6, 3)(7, 6)(5, 7)]