#![allow(unused_macros, unused_imports, dead_code)] use std::io::*; use std::collections::*; fn read_line() -> String { let mut s = String::new(); stdin().read_line(&mut s).unwrap(); s } macro_rules! from_iter { ($($a:ident),+ = $it:expr) => { $(let $a;)+ { let mut _it = $it.into_iter(); $($a = _it.next().unwrap();)+ assert!(_it.next().is_none()); } }; } macro_rules! from_str { ($($a:ident : $t:ty),+ = $s:expr) => { $(let $a: $t;)+ { let mut _it = $s.split_whitespace(); $($a = _it.next().unwrap().parse().unwrap();)+ assert!(_it.next().is_none()); } }; } macro_rules! from_line { ($($a:ident : $t:ty),+) => { $(let $a: $t;)+ { let _line = read_line(); let mut _it = _line.trim().split_whitespace(); $($a = _it.next().unwrap().parse().unwrap();)+ assert!(_it.next().is_none()); } }; } macro_rules! print_var_fmt { ($e:expr) => { concat!(stringify!($e), ":\t{}") }; ($e:expr, $($es: expr),+) => { concat!(print_var_fmt!($e), ",\t", print_var_fmt!($($es),+)) }; } macro_rules! dbg { ($($es:expr),+) => { writeln!(&mut io::stderr(), print_var_fmt!($($es),*), $($es),*); }; } fn main() { from_line!(n: u32); let mut arr = vec![0; 100002]; for _ in 0..n { from_line!(v: u32, w: u32); for i in (1..(100002-w as usize)).rev() { if arr[i] > 0 && arr[i] + v > arr[i+w as usize] { arr[i+w as usize] = arr[i] + v; } } if arr[w as usize] <= v { arr[w as usize] = v; } } from_line!(v: u32); let mut min = 0; for (i,x) in arr.iter().enumerate() { if *x == v { min = i; break; } } let mut max = min; for (i, x) in arr.iter().enumerate().skip(min + 1) { if *x <= v { max = i; } else { break; } } if min == 0 { println!("1"); } else { println!("{}", min); } if min == max || max > 100000 { println!("inf"); } else { println!("{}", max); } }