#include <iostream>
#include <cstdio>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <cstdlib>
using namespace std;
int A[100005];
int main() {
int T;
scanf("%d",&T);
while(T--) {
int n,m;
scanf("%d%d",&n,&m);
for(int i=0; i<n; i++) {
scanf("%d",&A[i]);
}
sort(A,A+n,less<int>() );
int pos1,pos2;
pos1=0;
int res=0;
while(pos1<n) {
int data;
data=m-A[pos1];
pos2=upper_bound(A,A+n,data)-A;
pos2=pos2-1;
if(pos2>pos1)
{
res=res+pos2-pos1;
}
pos1++;
}
printf("%d\n",res);
}
}
//就是练练upper_bound 和lower_bound 而已
无题 stl 二分
最新推荐文章于 2021-04-27 18:15:17 发布