Advertisement
TwITe

Untitled

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