import java.util.Map; import java.util.Scanner; import java.util.TreeMap; public class Main { public static void main(String[] args){ Main main = new Main(); main.solveC(); } private void solveC() { Scanner sc = new Scanner(System.in); final int N = sc.nextInt(); TreeMap map = new TreeMap<>(); map.put(0, 0); for (int i = 0; i < N; i++) { final int value = sc.nextInt(); final int weight = sc.nextInt(); TreeMap nextMap = new TreeMap<>(map); for (Map.Entry e : map.entrySet()) { final int prevWeight = e.getKey(); final int prevValue = e.getValue(); int nextWeight = prevWeight + weight; int nextValue = prevValue + value; if (!map.containsKey(nextWeight) || nextValue > map.get(nextWeight)) { nextMap.put(nextWeight, nextValue); } } map = nextMap; } final int V = sc.nextInt(); Integer min = null; Integer max = null; for (Map.Entry e : map.entrySet()) { final int weight = e.getKey(); final int value = e.getValue(); if (min == null && value == V) { min = weight; } if (value > V) { max = weight; break; } } System.out.println(min == null ? 1 : min); System.out.println(max == null ? "inf" : max - 1); } }