import java.util.Arrays; import java.util.Scanner; public class Main { static Scanner in = new Scanner(System.in); public static void main(String[] args) { int N = in.nextInt(); int[] v = new int[N], w = new int[N]; int sum = 0; for(int i = 0; i < N; i++){ v[i] = in.nextInt(); w[i] = in.nextInt(); sum += w[i]; } int V = in.nextInt(); int[][] dp = new int[N + 1][100001]; for(int i = 0; i < N; i++){ Arrays.fill(dp[i], 0); } for(int i = 1; i < N + 1; i++){ for(int j = 0; j < 100001; j++){ if(j - w[i - 1] >= 0){ dp[i][j] = Math.max(dp[i - 1][j], dp[i - 1][j - w[i -1]] + v[i - 1]); }else{ dp[i][j] = dp[i - 1][j]; } } } int min = 0, max = 0; for(int i = 1; i < dp[N].length; i++){ if(dp[N][i] == V){ min = i; break; } } for(int i = dp[N].length - 1; i > 0; i--){ if(dp[N][i] == V){ max = i; break; } } System.out.println(min); System.out.println(max > sum ? "inf" : max); } }