这是一道贪心水题。注意空行的控制就没有什么问题了。
#include<iostream>
#include<algorithm>#include<cstdio>
using namespace std;
const int ms = (1e5) + 10;
int inp[ms];
{
int t;
scanf("%d", &t);
bool isfirst = true;
while(t--)
{
if(isfirst)
isfirst = false;
else
printf("\n");
int n, m;
scanf("%d", &n);
scanf("%d", &m);
for(int i = 0; i < n; ++i)
scanf("%d", &inp[i]);
int ans = 0;
sort(inp, inp + n);
for(int i = 0, j = n-1; i <= j; ++i)
{
while(i <= j && inp[i] + inp[j] > m)
{
++ans;
--j;
}
if(i <= j)
{
--j;
++ans;
}
}
printf("%d\n", ans);
}
return 0;
}