inf = open("bank.in", "r")
ouf = open("bank.out", "w")

n, m = map(int, inf.readline().split())

d = []
for i in range(n):
	t, a, b = map(int, inf.readline().split())
	d += [[t, i, a, b]]

w = [0] * m

for i in range(n):
	best = w[0]
	bw = 0

	for j in range(1, m):
		if w[j] < best:
			best = w[j]
			bw = j

	d[i][0] = max(d[i][0], best) + d[i][2]
	w[bw] = d[i][0]

d.sort()

last = 0
for i in range(n):
	d[i][1], d[i][0] = max(d[i][0], last) + d[i][3], d[i][1]
	last = d[i][1]

d.sort()

for i in range(n):
	ouf.write("%d\n" % d[i][1])

