import sys input = sys.stdin.readline from bisect import bisect_left,bisect N,K=map(int,input().split()) TD=[list(map(int,input().split())) for i in range(N)] SUM=0 LIST=[] for t,d in TD: LIST.append(d) SUM+=d LIST.append(0) LIST.append(10**10) LIST=sorted(set(LIST)) OK=len(LIST)-1 NG=0 while OK>NG+1: mid=(OK+NG)//2 flag=0 x=-1<<30 for t,d in TD: if d>=LIST[mid]: if t-xLIST[OK-1]: a,b=DP[x] DP=[(-2000000000, 0),(t,d+b)] else: a,b=DP[x] DP.append((t,d+b)) #print(DP) while len(DP)>=2 and DP[-1][1]<=DP[-2][1]: DP.pop() print(LIST[OK-1]) print(SUM-DP[-1][1])