from operator import add import bisect from itertools import accumulate import sys input = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 7) inf = 10**18 class SparseTable: def __init__(self, N, arr, op, u): self.N = N self.depth = N.bit_length() self.op = op self.arr = tuple(arr) self.u = u self._build() def __call__(self, s, t): """ [s, t)区間(0-indexed)での値を返す """ if s == t: return self.u i = (t - s).bit_length() - 1 L = self.table[i][s] R = self.table[i][t - (1 << i)] return self.op(L, R) def _build(self): self.table = [] self.table.append(self.arr) N = self.N for i in range(self.depth - 1): shift = 1 << i N -= shift t = tuple(self.op(self.table[-1][j], self.table[-1][j+shift]) for j in range(N)) self.table.append(t) N, K = map(int, input().split()) T = [0] * N D = [0] * N for i in range(N): T[i], D[i] = map(int, input().split()) Dmax = SparseTable(N, D, max, 0) Dacc = [0] + list(accumulate(D)) Dsum = lambda s, t: Dacc[t] - Dacc[s] dp = [(inf, inf) for _ in range(N + 1)] dp[0] = (0, 0) for i in range(N): a, b = dp[i] #自分で処理 na = max(a, D[i]) nb = add(b, D[i]) if dp[i + 1] > (na, nb): dp[i + 1] = (na, nb) #姉が処理 to = bisect.bisect_left(T, T[i] + K) na = max(a, Dmax(i+1, to)) nb = add(b, Dsum(i+1, to)) if dp[to] > (na, nb): dp[to] = (na, nb) print(*dp[N], sep="\n")