贪心思想,排序后左右用两个变量往中间操作即可。
注意输出格式,格式不对会判WA而不是PE.
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
#include <ctype.h>
#include <iostream>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <assert.h>
#include <time.h>
#include <sstream>
typedef long long LL;
const int INF = 500000001;
const double EPS = 1e-9;
const double PI = acos(-1.0);
using namespace std;
int main()
{
#ifdef _Te3st
freopen("test0.in", "r", stdin);
freopen("test0.out", "w", stdout);
srand(time(NULL));
#endif
int T, n, l, a[100005];
scanf("%d", &T);
while(T--)
{
scanf("%d %d", &n, &l);
for(int i = 0; i < n; i++)
{
scanf("%d", &a[i]);
}
sort(a, a+n);
int left = 0, right = n - 1;
int ans = 0;
while(left <= right)
{
if(a[left] + a[right] > l)
{
--right;
}
else
{
--right;
++left;
}
++ans;
}
printf("%d\n", ans);
if(T) puts("");
}
return 0;
}