import sys input = sys.stdin.readline from heapq import heappop,heappush N,Y,Z=list(map(int,input().split())) A=[list(map(int,input().split())) for i in range(N)] Q=[] R=[] for c,l,x in A: if l<=Y: heappush(Q,(-x,c)) else: R.append((l,x,c)) R.sort(reverse=True) ANS=0 #print(Q) while Q and YY: need=(nec-Y+plus-1)//plus else: need=float("inf") use=min(need,ko) ko-=use Y+=plus*use ANS+=use if ko>0: heappush(Q,(-plus,ko)) while R: if R[-1][0]<=Y: l,x,c=R.pop() heappush(Q,(-x,c)) else: break if Y>=Z: print(ANS) else: print(-1)