#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 = """1 8 9 # 9 4 382593220 # """ # sys.stdin = io.StringIO(_INPUT) def main(): N, V, L = map(int, input().split()) x = [None for _ in range(N)] + [L] v = [None for _ in range(N)] w = [None for _ in range(N)] for i in range(N): x[i], v[i], w[i] = map(int, input().split()) if i == 0 and V - x[0] < 0: print(-1) return elif i >= 1 and x[i] - x[i-1] > V: print(-1) return if L - x[N-1] > V: print(-1) return dp = [[10**10 for _ in range(V+1)] for _ in range(N+1)] dp[0][V-x[0]] = 0 for i in range(N): d = x[i+1] - x[i] for v in range(V+1): if dp[i][v] < 10**10: if v-(x[i+1]-x[i]) >= 0: dp[i+1][v-d] = min(dp[i+1][v-d], dp[i][v]) dp[i+1][V-d] = min(dp[i+1][V-d], dp[i][v] + w[i]) MinW = min(dp[N]) if MinW == 10**10: print(-1) else: print(MinW) if __name__ == '__main__': main()