group_souvenir.cpp 657 B

1234567891011121314151617181920212223242526272829303132333435
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <algorithm>
  4. using namespace std;
  5. int main()
  6. {
  7. int limit, n;
  8. cin >> limit >> n;
  9. int* arr = new int[n];
  10. for (int i = 0; i < n; ++i) {
  11. scanf("%d", arr+i);
  12. }
  13. sort(arr, arr+n);
  14. int* left = arr, *right = arr+n-1;
  15. int result = 0;
  16. while (true) {
  17. if (left > right) break;
  18. if (left == right) {
  19. ++result;
  20. break;
  21. }
  22. if (*left + *right > limit) {
  23. ++result;
  24. --right;
  25. } else {
  26. ++result;
  27. ++left;
  28. --right;
  29. }
  30. }
  31. cout << result;
  32. return 0;
  33. }