import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.Map; import java.util.TreeMap; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] sa = br.readLine().split(" "); int n = Integer.parseInt(sa[0]); int m = Integer.parseInt(sa[1]); int l = Integer.parseInt(sa[2]); int[] x = new int[n]; int[] v = new int[n]; int[] w = new int[n]; for (int i = 0; i < n; i++) { sa = br.readLine().split(" "); x[i] = Integer.parseInt(sa[0]); v[i] = Integer.parseInt(sa[1]); w[i] = Integer.parseInt(sa[2]); } br.close(); if ((n + 1) * m < l) { System.out.println(-1); return; } TreeMap map = new TreeMap<>(); map.put(m, 0L); for (int i = 0; i < n; i++) { Map tm = map.tailMap(x[i]); if (tm.isEmpty()) { System.out.println(-1); return; } for (Integer o : tm.keySet().toArray(new Integer[0])) { int k = Math.min(x[i] + m, o + v[i]); if (map.containsKey(k)) { map.put(k, Math.min(map.get(k), tm.get(o) + w[i])); } else { map.put(k, tm.get(o) + w[i]); } } } long ans = Long.MAX_VALUE; Map tm = map.tailMap(l); if (tm.isEmpty()) { System.out.println(-1); return; } for (long val : tm.values()) { ans = Math.min(ans, val); } System.out.println(ans); } }