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, min_ws = -1; int max_v = -1; for(int i = 1; i <= ws_sum; i++){ if(DP[i] == V && min_v < 0){ min_v = i; min_ws = i; } if(DP[i] == V){ max_v = i; } } System.out.println(min_v); // これ合ってなさそう... (全部突っ込んだ場合だったら、max は分からないと返す) System.out.println(min_ws == ws_sum ? "inf" : ("" + max_v)); //System.out.println(Arrays.toString(DP)); } }