fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. using namespace std;
  4.  
  5. int main() {
  6. int n,x;
  7. cin >> n >> x;
  8. int p[n];
  9. for (int i=0;i<n;i++) {
  10. cin >> p[i];
  11. }
  12. sort(p,p+n);
  13. int i=0,j=n-1,d=0;
  14. while (i<=j) {
  15. if (p[i]+p[j]<=x) {
  16. i++;
  17. }
  18. j--;
  19. d++;
  20. }
  21. cout << d;
  22. }
Success #stdin #stdout 0.01s 5320KB
stdin
4 10
7 2 3 9
stdout
3