Link to this code:
https://cses.fi/paste/56c2246f697c07422656cd//*
author: @ankingcodes
created: 2021-07-14 17:34:45.168337
*/
#include<bits/stdc++.h>
#include<algorithm>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define MOD 1000000007
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update> PBDS;
typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag,
tree_order_statistics_node_update> pairPBDS;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n, k; cin>>n>>k;
vector<ll> a(n);
for(auto &i: a) cin>>i;
sort(a.begin(), a.end());
ll i = 0, j = a.size() - 1;
ll ans = 0;
bool mark[n] = {false};
while (i < j) {
if (a[i] + a[j] <= k) {
ans += 1;
mark[i] = mark[j] = true;
i++; j--;
} else j--;
}
for (ll i=0;i<n;i++) {
ans += (mark[i]==false);
}
cout << ans << endl;
return 0;
}