const LIMIT: usize = 100000; fn main() { let mut n = String::new(); std::io::stdin().read_line(&mut n).ok(); let n: usize = n.trim().parse().unwrap(); let items = (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]) }) .collect::>(); let mut v = String::new(); std::io::stdin().read_line(&mut v).ok(); let v: usize = v.trim().parse().unwrap(); let mut dp = vec![vec![0usize; LIMIT+1]; n+1]; for i in 0..n { let (v, w) = items[i]; for j in 0..=LIMIT { dp[i+1][j] = dp[i+1][j].max(dp[i][j]); if j+w <= LIMIT { dp[i+1][j+w] = dp[i+1][j+w].max(dp[i][j] + v); } } } let mut min_flg = false; let mut max_flg = false; for i in 1..=LIMIT { if !min_flg && dp[n][i] == v { min_flg = true; println!("{}", i); } if i > 0 && dp[n][i-1] == v && dp[n][i] > v { max_flg = true; println!("{}", i-1); } } if !max_flg { println!("inf"); } }