use std::collections::{HashMap, HashSet}; fn main() { proconio::input! { n: usize, m:usize, k:usize, a: [[u64; m]; n], } let mut dp = vec![false; k as usize + 1]; dp[0] = true; for i in 0..n { let mut next = vec![false; k as usize + 1]; for j in 0..k as usize { if !dp[j] { continue; } for l in 0..m { if j + a[i][l] as usize <= k as usize { next[j + a[i][l] as usize] = true; } } } dp = next; } println!( "{}", dp.iter() .enumerate() .rfind(|x| *x.1) .map(|x| (k - x.0) as i64) .unwrap_or(-1) ); }