import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.PriorityQueue; import java.util.Scanner; public class Main { public static int RANGE = 100; public static void main(String[] args) { Scanner sc = new Scanner(System.in); final int N = sc.nextInt(); int[] vs = new int[N]; int[] ws = new int[N]; int ws_sum = 0; for(int i = 0; i < N; i++){ vs[i] = sc.nextInt(); ws[i] = sc.nextInt(); ws_sum += ws[i]; } final int V = sc.nextInt(); int[] DP = new int[ws_sum + 1]; for(int i = 0; i < N; i++){ for(int w = ws_sum - ws[i]; w >= 0; w--){ DP[w + ws[i]] = Math.max(DP[w + ws[i]], DP[w] + vs[i]); } } int min_v = -1; int max_v = -1; for(int i = 1; i <= ws_sum; i++){ if(DP[i] == V && min_v >= 0){ max_v = i; } if(DP[i] == V && min_v < 0){ min_v = i; } } System.out.println(min_v); System.out.println(max_v < 0 ? "inf" : ("" + max_v)); //System.out.println(Arrays.toString(DP)); } }