import sys input = lambda :sys.stdin.readline()[:-1] ni = lambda :int(input()) na = lambda :list(map(int,input().split())) yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES") no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO") ####################################################################### from collections import defaultdict n, y, z = na() c, l, x = zip(*[na() for i in range(n)]) idx = sorted(range(n), key = lambda x: l[x]) ans = 0 i = 0 from heapq import * hq = [] L = [] for i in idx: if l[i] < z: L.append(l[i]) L.append(z) i = 0 for z in L: while i < n and l[idx[i]] <= y: heappush(hq, (-x[idx[i]], c[idx[i]])) i += 1 # print(hq, i, idx) while y < z and hq: xx, cc = heappop(hq) xx = -xx d = max(0, min(cc, (z - y - 1) // xx + 1)) if d < cc: heappush(hq, (-xx, cc - d)) ans += d y += xx * d # print(y, z, hq, ans) if y < z: print(-1) exit() print(ans)