import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int volume = sc.nextInt(); int length = sc.nextInt(); TreeMap base = new TreeMap<>(); base.put(volume, 0L); int prev = 0; for (int i = 0; i < n; i++) { int x = sc.nextInt(); int v = sc.nextInt(); long w = sc.nextInt(); TreeMap next = new TreeMap<>(); for (int y : base.keySet()) { long value = base.get(y); int none = y - x + prev; if (none >= 0) { Integer key = next.ceilingKey(none); if (key == null || next.get(key) > value) { next.put(none, value); key = none; while ((key = next.lowerKey(key)) != null) { if (next.get(key) >= value) { next.remove(key); } else { break; } } } int full = Math.min(volume, none + v); key = next.ceilingKey(full); if (key == null || next.get(key) > value + w) { next.put(full, value + w); key = full; while ((key = next.lowerKey(key)) != null) { if (next.get(key) >= value + w) { next.remove(key); } else { break; } } } } } prev = x; base = next; } for (int y : base.keySet()) { if (y - length + prev >= 0) { System.out.println(base.get(y)); return; } } System.out.println(-1); } }