Advertisement
TwITe

Untitled

Aug 21st, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. struct shoes_compare {
  2.     bool operator()(int left, int right) {
  3.         return (right - left >= 3 || right == left)
  4.     }
  5. };
  6.  
  7.  
  8. void task2() {
  9.     int customer_size, n;
  10.     cin >> customer_size >> n;
  11.     vector <int> shoes;
  12.     for (int i = 0; i < n; i++) {
  13.         int current_shoes;
  14.         cin >> current_shoes;
  15.         shoes.push_back(current_shoes);
  16.     }
  17.     sort(shoes.begin(), shoes.end());
  18.     auto it = lower_bound(shoes.begin(), shoes.end(), customer_size, shoes_compare());
  19.     int valid_shoes = 0;
  20.     if (it != shoes.end()) {
  21.         valid_shoes = 1;
  22.     }
  23.     else {
  24.         cout << valid_shoes;
  25.         return;
  26.     }
  27.     auto last_valid_shoes = it;
  28.     for (it = it + 1; it != shoes.end(); it++) {
  29.         if ((*it - *(last_valid_shoes)) >= 3) {
  30.             valid_shoes++;
  31.             last_valid_shoes = it;
  32.         }
  33.     }
  34.     cout << valid_shoes;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement