fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. typedef long long ll;
  6. typedef pair<int, int> ii;
  7.  
  8. const int INF = 1e9;
  9. const ll LINF = 1e18;
  10.  
  11. const int N = 2e5 + 5;
  12.  
  13. int n, x;
  14. int a[N];
  15.  
  16. int main() {
  17. ios::sync_with_stdio(false);
  18. cin.tie(nullptr);
  19. cin >> n >> x;
  20. for (int i = 1; i <= n; i++) cin >> a[i];
  21.  
  22. sort(a + 1, a + n + 1);
  23.  
  24. int ans = 0;
  25. int l = 1, r = n;
  26. while (l <= r) {
  27. if (a[l] + a[r] <= x) l++;
  28. r--;
  29. ans++;
  30. }
  31.  
  32. cout << ans << '\n';
  33. }
Success #stdin #stdout 0.01s 5280KB
stdin
4 10
7 2 3 9
stdout
3