import sys; input = sys.stdin.buffer.readline sys.setrecursionlimit(10**7) from collections import defaultdict con = 10 ** 9 + 7; INF = float("inf") def getlist(): return list(map(int, input().split())) #処理内容 def main(): N, V, L = getlist() DP = [[INF] * (V + 1) for i in range(N + 2)] DP[0][V] = 0 xnow = 0 for i in range(1, N + 1): x, v, w = getlist() for j in range(V + 1): if j >= v: DP[i][j] = min(DP[i][j], DP[i][j - v] + w) if j + (x - xnow) <= V: DP[i][j] = min(DP[i][j], DP[i - 1][j + (x - xnow)]) xnow = x for j in range(V + 1): if j + (L - xnow) <= V: DP[N + 1][j] = min(DP[N + 1][j], DP[N][j + (L - xnow)]) # print(DP) ans = min(DP[-1]) if ans == INF: print(-1) else: print(ans) if __name__ == '__main__': main()