#[allow(unused_imports)] use std::cmp::{max, min}; #[allow(unused_imports)] use std::collections::{HashMap, HashSet}; mod util { use std::io::stdin; use std::str::FromStr; use std::fmt::Debug; #[allow(dead_code)] pub fn line() -> String { let mut line: String = String::new(); stdin().read_line(&mut line).unwrap(); line.trim().to_string() } #[allow(dead_code)] pub fn get() -> T where ::Err: Debug, { let mut line: String = String::new(); stdin().read_line(&mut line).unwrap(); line.trim().parse().unwrap() } #[allow(dead_code)] pub fn gets() -> Vec where ::Err: Debug, { let mut line: String = String::new(); stdin().read_line(&mut line).unwrap(); line.split_whitespace() .map(|t| t.parse().unwrap()) .collect() } #[allow(dead_code)] pub fn get2() -> (T, U) where ::Err: Debug, ::Err: Debug, { let mut line: String = String::new(); stdin().read_line(&mut line).unwrap(); let mut iter = line.split_whitespace(); ( iter.next().unwrap().parse().unwrap(), iter.next().unwrap().parse().unwrap(), ) } } fn main() { let n: usize = util::get(); let vw: Vec<(usize, usize)> = (0..n).map(|_| util::get2()).collect(); let v: usize = util::get(); let inf = 1e9 as usize; let mut dp = vec![vec![inf as usize; 100000 + 2]; n + 1]; dp[0][0] = 0; for i in 1..n + 1 { let vi = vw[i - 1].0; let wi = vw[i - 1].1; for k in (0..dp[i].len()).rev() { if k + 1 < dp[i].len() { dp[i][k] = min(dp[i][k], dp[i][k + 1]); } if k >= vi { dp[i][k] = min(dp[i][k], dp[i - 1][k - vi] + wi); } dp[i][k] = min(dp[i][k], dp[i - 1][k]); } } println!("{}", max(1, dp[n][v])); if dp[n][v + 1] != inf { println!("{}", dp[n][v + 1] - 1); } else { println!("inf"); } }