Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct shoes_compare {
- bool operator()(int left, int right) {
- if (left - right >= 3 || right == left) {
- return true;
- }
- else {
- return false;
- }
- }
- };
- void task2() {
- int customer_size, n;
- cin >> customer_size >> n;
- vector <int> shoes;
- for (int i = 0; i < n; i++) {
- int current_shoes;
- cin >> current_shoes;
- shoes.push_back(current_shoes);
- }
- sort(shoes.begin(), shoes.end());
- auto it = lower_bound(shoes.begin(), shoes.end(), customer_size, shoes_compare());
- int valid_shoes = 0;
- if (it != shoes.end()) {
- valid_shoes = 1;
- }
- else {
- cout << valid_shoes;
- return;
- }
- auto last_valid_shoes = it;
- for (it = it + 1; it != shoes.end(); it++) {
- if ((*it - *(last_valid_shoes)) >= 3) {
- valid_shoes++;
- last_valid_shoes = it;
- }
- }
- cout << valid_shoes;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement