#include <bits/stdc++.h> #define all(x) x.begin(), x.end() #define len(x) (int)(x.size()) #define mp make_pair #define pb push_back #define fi first #define se second using namespace std; typedef pair<int, int> pii; typedef long long ll; typedef long double ld; bool umin(int& a, int b) { if(b < a) { a = b; return true; } return false; } bool umax(int& a, int b) { if(b > a) { a = b; return true; } return false; } //#ifdef KoRoVa //#define DEBUG for (bool __DEBUG=1;__DEBUG;__DEBUG=0) //#define LOG(...) prnt(#__VA_ARGS__" ::",_VA_ARGS)<<endl //#else //#define DEBUG while(false) //#define LOG(...) if(false) //#endif template <class ...Ts> auto &prnt(Ts ...ts) { return ((cerr << ts << " "), ...); } const int max_n = -1, inf = 1000111222; const ll linf = 1000111222000111222; inline int brute (int n, int k, vector <int> a) { sort(all(a)); int ans = inf; do { int res = 0, sum = 0, cnt = 0; for (int i = 0; i < n; i++) { sum += a[i]; ++cnt; if (sum >= k || cnt == 3) { if (i + 1 < n) { ++res; } sum = 0; cnt = 0; } } umin(ans, res); } while (next_permutation(all(a))); return ans; } const int debug = false; const int C = 15; mt19937 rng(228); inline int randll(int l, int r) { return uniform_int_distribution<int>(l, r) (rng); } void test_case() { int n, k; if (!debug) { cin >> n >> k; } else { n = randll(1, 7); k = randll(1, C); } int d[n]; vector <int> A; for(int i = 0; i < n; i++) { if (!debug) { cin >> d[i]; } else { int x = randll(1, C); d[i] = x; A.pb(x); } } sort(d, d + n); int l = 0, r = n/2; while(r - l > 0) { int mid = (l + r + 1) / 2; bool ok = true; for(int i = 0; i < mid; i++) { if(d[i] + d[mid * 2 - 1 - i] >= k) { ok = false; break; } } if(ok) l = mid; else r = mid - 1; } int cntK = 0; for(int i = 0; i < n; i++) { if(d[i] >= k) cntK++; } int ans = n; for(int i = 0; i <= l; i++) { int pair = i, K = cntK, left_less_than_K = n - 2 * i - K; int triple_with_K = min(pair, K); K -= triple_with_K; pair -= triple_with_K; int triple_without_K = min(pair, left_less_than_K); pair -= triple_without_K; left_less_than_K -= triple_without_K; int res = 0; if(pair == 0) { int can_pair = min(K, left_less_than_K); K -= can_pair; left_less_than_K -= can_pair; res = triple_with_K + triple_without_K + can_pair + K + (left_less_than_K + 1) / 2; } else { res = triple_with_K + triple_without_K + (pair * 2 + 2) / 3; } res--; // if(K + pair * 2 + left_less_than_K + 1 == 0) res--; //only triples, last triple doesn't count // else { //have something apart from triples // if(left_less_than_K % 2 == 0 || K > 0) res--; // } umin(ans, res); } cout<<ans<<'\n'; if (debug) { int res = brute(n, k, A); if (res != ans) { cout << res << ' ' << ans << '\n' << '\n'; cout << n << ' ' << k << '\n'; for(auto &i : A) { cout << i << '\n'; } exit(4); } assert(res == ans); // cout << "done" << endl; } } signed main() { // freopen("input.txt", "r", stdin); ios_base::sync_with_stdio(false); cin.tie(nullptr); int testcases = 1; cin >> testcases; while(testcases--) test_case(); exit(0); }