#region Header #!/usr/bin/env python3 # from typing import * import sys import io import math import collections import decimal import itertools from queue import PriorityQueue import bisect import heapq def input(): return sys.stdin.readline()[:-1] sys.setrecursionlimit(1000000) #endregion # _INPUT = """5 8 11 # 2 2 231985796 # 6 0 190979457 # 7 2 373925694 # 8 2 976892608 # 8 1 184831039 # """ # sys.stdin = io.StringIO(_INPUT) def main(): N, V, L = map(int, input().split()) x = [0] + [None for _ in range(N)] + [L] v = [0] + [None for _ in range(N)] + [0] w = [0] + [None for _ in range(N)] + [0] for i in range(N): x[i+1], v[i+1], w[i+1] = map(int, input().split()) if x[i+1] - x[i] > V: print(-1) return if x[N+1] - x[N] > V: print(-1) return dp = [10**10 for _ in range(V+1)] dp[V] = 0 for i in range(N+1): dp1 = [10**10 for _ in range(V+1)] d = x[i+1] - x[i] for v1 in range(V+1): if dp[v1] < 10**10: if v1-(x[i+1]-x[i]) >= 0: dp1[v1-d] = min(dp1[v1-d], dp[v1]) v_filled = min(v1+v[i], V) if v_filled - d >= 0: dp1[v_filled-d] = min(dp1[v_filled-d], dp[v1] + w[i]) dp = dp1 MinW = min(dp) if MinW == 10**10: print(-1) else: print(MinW) if __name__ == '__main__': main()