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)] dis_list = [shop_list[0][0]] + [(shop_list[i + 1][0] - shop_list[i][0]) for i in range(len(shop_list) - 1)] + [L - shop_list[-1][0]] dp_dict = {} def solve(i, j): j -= dis_list[i] if j < 0: return -1 if i == N: return 0 if (i, j) in dp_dict: return dp_dict[(i, j)] a = solve(i + 1, j) b = solve(i + 1, j + shop_list[i][1] if j + shop_list[i][1] < V else V) if a == -1 and b == -1: dp_dict[(i, j)] = -1 return -1 elif a == -1: res = b + shop_list[i][2] dp_dict[(i, j)] = res return res else: res = min([a, b + shop_list[i][2]]) dp_dict[(i, j)] = res return res print(solve(0, V))