const INF: usize = 1000000000000000000; fn main() { let (n, x, y): (usize, usize, usize) = { // 定数個の整数を受け取り, 定数個の変数に束縛する let mut line: String = String::new(); std::io::stdin().read_line(&mut line).unwrap(); let mut iter = line.split_whitespace(); ( iter.next().unwrap().parse().unwrap(), iter.next().unwrap().parse().unwrap(), iter.next().unwrap().parse().unwrap() ) }; let mut a = Vec::new(); let mut b = Vec::new(); let mut c = Vec::new(); for _ in 0..n { let (p, q, r): (usize, usize, usize) = { // 定数個の整数を受け取り, 定数個の変数に束縛する let mut line: String = String::new(); std::io::stdin().read_line(&mut line).unwrap(); let mut iter = line.split_whitespace(); ( iter.next().unwrap().parse().unwrap(), iter.next().unwrap().parse().unwrap(), iter.next().unwrap().parse().unwrap() ) }; a.push(p); b.push(q); c.push(r); } let mut dp = vec![vec![INF; y + 1]; x + 1]; dp[0][0] = 0; for i in 0..n { for j in (0..x+1).rev() { for k in (0..y+1).rev() { if a[i] <= j && b[i] <= k { dp[j][k] = dp[j][k].min(dp[j - a[i]][k - b[i]] + c[i]); } } } } let mut ans = 0; for i in 0..x+1 { for j in 0..y+1 { if dp[i][j] != INF { ans = ans.max(dp[i][j]); } } } println!("{}", ans); }