Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int find_max_apples(int max_size_difference, vector<int> apple_sizes) {
- int n = apple_sizes.size();
- sort(apple_sizes.begin(), apple_sizes.end());
- int j = 0, mx = 0;
- for(int i = 0; i < n; i++) {
- while(j < n && apple_sizes[j] - apple_sizes[i] <= max_size_difference) {
- j++;
- }
- mx = max(mx, j- i);
- }
- return mx;
- }
- int main()
- {
- int max_size_difference, n;
- cin >> max_size_difference >> n;
- vector<int> apple_sizes(n);
- for(int i = 0; i < n; i++) {
- cin >> apple_sizes[i];
- }
- cout << find_max_apples(max_size_difference, apple_sizes);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment