var a,k:array[0..1000000]of longint;
b,c,d,e,f,g,h,i,j,l,n,m,mid:longint;
begin
assign(input,'count.in');
assign(output,'count.out');
reset(input);
rewrite(output);
read(b,f);
e:=0;
n:=0;
l:=1;
for c:=1 to b do
begin
read(d);
k[d]:=k[d]+1;
end;
while l<=b do
begin
for m:=1 to k[n] do
begin
a[l]:=n;
l:=l+1;
end;
n:=n+1;
end;
e:=0;
for c:=1 to b do
begin
i:=c+1;
j:=b;
while (j>=i) do
begin
mid:=(j+i) div 2;
if a[mid]+a[c]>f then j:=mid-1 else i:=mid+1;
end;
e:=e+(j-c);
end;
writeln(e);
close(input);
close(output);
end.
c++方法:(有BUG)
#include
using namespace std;
int main()
{
int n,s,a[100001],k=0;
cin>>n>>s;
for(int i=1;i<=n;i++)cin>>a[i];
sort(a+1,a+n+1);
for(int i=1;i<=n;i++)
{
for(int j=i+1;j<=n;j++)
{
if(a[i]+a[j]<=s)k++;
}
}
cout<
}
var
begin
readln(n,s);
for i:=1 to n do read(a[i]);
for i:=1 to n do
begin
for j:=1 to n do
if a[i]+a[j] end;
writeln(k);
end.