import java.util.*; import java.math.*; public class Main { static int[][] dp; static int[] wArr; static int[] vArr; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int wTotal = 0; int vTotal = 0; wArr = new int[n + 1]; vArr = new int[n + 1]; for (int i = 1; i <= n; i++) { vArr[i] = sc.nextInt(); vTotal += vArr[i]; wArr[i] = sc.nextInt(); wTotal += wArr[i]; } int value = sc.nextInt(); if (value == vTotal) { System.out.println(wTotal); System.out.println("inf"); return; } dp = new int[n + 1][wTotal]; int maxLeft = 0; int maxRight = wTotal; while (maxRight - maxLeft > 1) { int m = (maxLeft + maxRight) / 2; if (dfw(n, m) > value) { maxRight = m; } else { maxLeft = m; } } int max = maxLeft; int min; if (value == 0) { min = 1; } else { int minLeft = 0; int minRight = wTotal; while (minRight - minLeft > 1) { int m = (minLeft + minRight) / 2; if (dfw(n, m) >= value) { minRight = m; } else { minLeft = m; } } min = minRight; } System.out.println(min); System.out.println(max); } static int dfw(int idx, int weight) { if (weight < 0) { return Integer.MIN_VALUE; } if (weight == 0) { return 0; } if (idx == 0) { return 0; } if (dp[idx][weight] != 0) { return dp[idx][weight]; } dp[idx][weight] = Math.max(dfw(idx - 1, weight), dfw(idx - 1, weight - wArr[idx]) + vArr[idx]); return dp[idx][weight]; } }