INF = 1 << 25 n = gets.to_i ITEM = n.times.map{gets.split.map(&:to_i)} V = gets.to_i + 1 dp = Array.new(V+2, INF) dp[0] = 0 ITEM.each do |v,w| V.downto(0) do |i| if i < v && w < dp[i] dp[i] = w elsif i >= v && dp[i - v] + w < dp[i] dp[i] = dp[i - v] + w end end end puts dp[V-1] == 0 ? 1 : dp[V-1] puts dp[V] < 10 ** 5 ? dp[V] - 1 : "inf"