from collections import deque, defaultdict, Counter from bisect import bisect_left, bisect_right from itertools import permutations, combinations, groupby from heapq import heappop, heappush import math, sys input = lambda: sys.stdin.readline().rstrip("\r\n") def printl(li, sep=" "): print(sep.join(map(str, li))) def yn(flag): print(Yes if flag else No) _int = lambda x: int(x)-1 MOD = 998244353 #10**9+7 INF = 1<<60 Yes, No = "Yes", "No" N, Y, Z = map(int, input().split()) LXC = [] for _ in range(N): c, l, x = map(int, input().split()) LXC.append((l, x, c)) LXC.sort(reverse=True) q = [] def add(): while LXC and LXC[-1][0] <= Y: l, x, c = LXC.pop() heappush(q, (-x, c)) add() ans = 0 while q and Y < Z: x, c = heappop(q) x = -x if LXC: nxt = min(LXC[-1][0], Z) else: nxt = Z need = nxt-Y if need > x*c: ans += c Y += x*c else: cnt = -(-need//x) ans += cnt Y += x*cnt if c-cnt > 0: heappush(q, (-x, c-cnt)) add() print(ans if Y >= Z else -1)