import bisect n, k = map(int, input().split()) tasks = [] for _ in range(n): t, d = map(int, input().split()) tasks.append((t, d)) # Sort tasks by descending D, then ascending T tasks.sort(key=lambda x: (-x[1], x[0])) scheduled = [] added_times = set() for t, d in tasks: # Check if this task can be added low = t - k + 1 high = t + k - 1 # Find the left and right positions in the scheduled list left = bisect.bisect_left(scheduled, low) right = bisect.bisect_right(scheduled, high) if left == right: # No existing tasks in the range [low, high] bisect.insort(scheduled, t) added_times.add(t) # Collect all tasks not in scheduled max_d = 0 sum_d = 0 for t, d in tasks: if t not in added_times: if d > max_d: max_d = d sum_d += d print(max_d) print(sum_d)