use std::cmp::*; use std::io::*; const INF: usize = 40; fn main() { let mut s: String = String::new(); std::io::stdin().read_to_string(&mut s).ok(); let mut itr = s.trim().split_whitespace(); let n: usize = itr.next().unwrap().parse().unwrap(); let v: usize = itr.next().unwrap().parse().unwrap(); let l: usize = itr.next().unwrap().parse().unwrap(); let mut a = Vec::new(); a.push((0, 0, 0)); for _ in 0..n { a.push(( itr.next().unwrap().parse().unwrap(), itr.next().unwrap().parse().unwrap(), itr.next().unwrap().parse().unwrap(), )); } a.push((l, 0, 0)); let mut dp: Vec> = vec![vec![INF; 11]; 11]; dp[0][v] = 0; for i in 0..n + 1 { for j in 0..v + 1 { let k = min(j + a[i].1, v); let diff = a[i + 1].0 - a[i].0; if k >= diff { dp[i + 1][k - diff] = min(dp[i + 1][k - diff], dp[i][j] + a[i].2); } if j >= diff { dp[i + 1][j - diff] = min(dp[i + 1][j - diff], dp[i][j]); } } } let mut ans = INF; for i in 0..v + 1 { if dp[n + 1][i] != INF { ans = min(ans, dp[n + 1][i]); } } if ans == INF { println!("-1",) } else { println!("{}", ans); } }