const INF: usize = 1usize << 60; fn main() { let mut nvl = String::new(); std::io::stdin().read_line(&mut nvl).ok(); let nvl: Vec = nvl.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let n = nvl[0]; let v = nvl[1]; let l = nvl[2]; let mut points = (0..n).map(|_| { let mut temp = String::new(); std::io::stdin().read_line(&mut temp).ok(); let temp: Vec = temp.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); (temp[0], temp[1], temp[2]) }) .collect::>(); points.insert(0, (0, 0, 0)); points.push((l, 0, 0)); let mut dp = vec![vec![INF; v+1]; n+2]; dp[0][v] = 0; for i in 1..=n+1 { let (cx, cv, cw) = points[i]; let (px, _, _) = points[i-1]; let diff = cx - px; if diff > v { println!("-1"); return; } for j in 0..=v { if j+diff <= v { dp[i][j] = dp[i][j].min(dp[i-1][j+diff]); let nj = (j + cv).min(v); dp[i][nj] = dp[i][nj].min(dp[i-1][j+diff] + cw); } } } println!("{}", dp[n+1].iter().min().unwrap()); }