import sys sys.setrecursionlimit(10**6) N, V, L = list(map(int, input().split())) shop_list = [list(map(int, input().split())) for i in range(N)] dp_dict = {} def solve(i, j): if j < 0: return -1 if (i, j) in dp_dict: return dp_dict[(i, j)] if i == N - 1: dis = L - shop_list[i][0] if j >= dis: dp_dict[(i, j)] = 0 return 0 elif j + shop_list[i][1] if j + shop_list[i][1] < V else V >= dis: dp_dict[(i, j)] = shop_list[i][2] return shop_list[i][2] else: dp_dict[(i, j)] = -1 return -1 dis = shop_list[i + 1][0] - shop_list[i][0] a = solve(i + 1, j - dis) j += shop_list[i][1] if j > V: j = V b = solve(i + 1, j - dis) + shop_list[i][2] if a == -1 and b == -1: dp_dict[(i, j)] = -1 return -1 else: if a == -1: dp_dict[(i, j)] = b return b elif b == -1: dp_dict[(i, j)] = a return a else: res = min([a, b]) dp_dict[(i, j)] = res return res if V - shop_list[0][0] < 0: print(-1) else: print(solve(0, V - shop_list[0][0]))