<Problem>
http://ntucoder.net/Problem/Details/48
Uses Crt;
Var n,i,j,k:longint; a:array[1..1000000] of longint; kq:int64;
Procedure Sort(l,r:longint);
var i,j,x,tg:longint;
begin
i:=l; j:=r; x:=a[(l+r) div 2];
repeat
while a[i]<x do inc(i); while x<a[j] do dec(j);
if i<=j then begin tg:=a[i]; a[i]:=a[j]; a[j]:=tg; inc(i); dec(j); end;
until i>j;
if l<j then sort(l,j);
if i<r then sort(i,r);
end;
Begin
readln(n,k);
for i:=1 to n do read(a[i]);
sort(1,n);
//for i:=1 to n do write(a[i],' ');
kq:=0;
j:=n;
for i:=n downto 1 do
begin
if a[i]+k<=a[j] then dec(j) //cai lon nhat se tim cai lon thu 2 thoa man a[i]+k<=a[j]
else inc(kq,a[i]); //Lay Bup be lon nhat de dung bup be nhor hon-> tiet kiem khong gian
end;
writeln(kq);
readln;
End.