""" sliding window aggrigation モノイドのqueueを管理する fold_all: すべてをたたみこむ popleft append """ from itertools import accumulate from collections import deque class SWAG: def __init__(self, operator_M, e_M): self.op_M = operator_M self.op_rev = lambda x,y: self.op_M(y,x) self.e_M = e_M self.q = deque([]) self.accL = [] self.accR = e_M self.L = self.R = 0 def build(self,lst): self.q = deque(lst) self.L = len(lst) self.accL = list(accumulate(reversed(lst),self.op_rev)) def __len__(self): return self.L + self.R def fold_all(self): if self.L: return self.op_M(self.accL[-1],self.accR) else: return self.accR def append(self,x): self.q.append(x) self.accR = self.op_M(self.accR,x) self.R += 1 def popleft(self): if self.L: self.accL.pop() self.L -= 1 return self.q.popleft() elif self.R: v = self.q.popleft() self.L,self.R = self.R-1,0 self.accL = list(accumulate(reversed(self.q),self.op_rev)) self.accR = self.e_M return v else: assert 0 def __repr__(self): return "{}\naccL:{}, accR:{}".format(self.q,self.accL,self.accR) # coding: utf-8 # Your code here! import sys readline = sys.stdin.readline read = sys.stdin.read n,V,L = [int(i) for i in readline().split()] xvw = [[int(i) for i in readline().split()] for _ in range(n)] n += 1 xvw.append([L,0,0]) INF = 10**18 dp = [INF]*(V+1) dp[V] = 0 D = [xvw[0][0]] + [xvw[i+1][0]-xvw[i][0] for i in range(n-1)] for (x,v,w),d in zip(xvw,D): ndp = [INF]*(V+1) for i in range(V+1-d): ndp[i] = dp[i+d] for i in range(V,-1,-1): ndp[min(i+v,V)] = min(ndp[min(i+v,V)],ndp[i]+w) dp = ndp #print(dp) x = min(dp) if x == INF: print(-1) else: print(x)