/MOBI - Đặt trạm phủ sóng (OLP 30/4 Khối 10)

<Problem>

http://ntucoder.net/Problem/Details/4408
              Uses Crt,math;
        Var  n,last,i,x,y,k:longint; t:array[-10..1000000] of int64; kq:int64;
        Begin
            readln(n,k);
            last:=-maxlongint;
            for i:=1 to n do
             begin
                 read(x,y);
                 t[x]:=y;
                 last:=max(last,x);
             end;
            //t[0]:=0;
        
            for i:=1 to last do t[i]:=t[i-1]+t[i];
        
            //kq:=-maxlongint;
            if last<=k*2+1 then begin writeln(t[last]); exit; end;
            for i:=k to last-k do    //thuat toan chi hoat dong tren khoang (-oo;last) khong hoat dong khi last<=k*2+1
             begin
                 kq:=max(t[i+k]-t[i-(k+1)],kq);
                 //writeln(i,' ',kq,' ','--');
             end;
        
            writeln(kq);
            readln;
        End.