void main(){ import std.stdio, std.string, std.conv, std.algorithm; int n, k; rd(n, k); auto t=new int[](n), d=new long[](n); foreach(i; 0..n) rd(t[i], d[i]); bool ch(long y){ // yよりむずいの全部解けるか for(int i=0, T=0; iy){ if(t[i]1){ auto md=(ok+ng)/2; ch(md) ? ok : ng = md; } long mx1=ok; if(mx1==0){writeln(0); writeln(0); return;} int[] idx; for(int i=0, j=-1; imx1){ for(int x=j+1; x=0){ if(t[j]+k<=t[x] && t[x]+k<=t[i]) idx~=x; }else{ if(t[x]+k<=t[i]) idx~=x; } } j=i; } for(int i=n-1; i>=0; i--)if(d[i]>mx1){ for(int j=i+1; jr+((e<=mx1)?e:0L))(0L, d)); return; } rec[0]=d[idx[0]]; for(int i=1, j=0; ir+((e>mx1)?e:0L))(0L, d)-rec[m-1]); } void chmax(T)(ref T x, T y){ if(x