fork download
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. template<typename It, typename T>
  8. bool contains_n_gt_x(It first, It last, size_t n, const T& x) {
  9. for (auto curr = first; first != last;) {
  10. first = find_if(curr, last, [&](const auto& y){ return x < y; });
  11. curr = find_if(first, last, [&](const auto& y){ return !(x < y); });
  12. if (distance(first, curr) >= n) return true;
  13. }
  14. return false;
  15. }
  16.  
  17. int main() {
  18. std::vector<int> v{10, 25, 41, 42, 43, 40, 8, 41, 42, 7, 49, 50, 61, 55, 45, 34, 10, 8};
  19. cout << contains_n_gt_x(begin(v), end(v), 5, 40) << endl;
  20. }
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
1