#!/usr/bin/ python3.8 import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np N, K = map(int, readline().split()) TD = np.array(read().split(), np.int64) T = TD[::2] D = TD[1::2] INF = 2 * 10 ** 9 T = np.concatenate([[-INF], T]) D = np.concatenate([[0], D]) def find_X(): def test(X): # X 以上をさぼれる A = T[D >= X] if not len(A): return True return np.all(np.diff(A) >= K) left = 0 right = 10 ** 9 + 10 while left + 1 < right: x = (left + right) // 2 if test(x): right = x else: left = x return left X = find_X() I = np.searchsorted(T, T - K, side='right') - 1 last_take = 0 D = D.tolist() I = I.tolist() dp = [0] * len(D) dp_cum = [0] * len(D) for n, (i, x) in enumerate(zip(I[1:], D[1:]), 1): if i >= last_take: dp[n] = dp_cum[i] + x dp_cum[n] = max(dp_cum[n - 1], dp[n]) if x > X: last_take = n yuki = dp_cum[-1] answer = sum(D) - yuki print(X) print(answer)