import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np *data, = map(int,read().split()) N = data[0] V = data[1:1+N+N:2] W = data[2:1+N+N:2] v_max = data[-1] # w -> v dp = np.zeros(10**5+1, np.int64) for v,w in zip(V,W): np.maximum(dp[w:], dp[:-w] + v, out=dp[w:]) np.maximum.accumulate(dp, out=dp) I = np.where(dp == v_max)[0] print(max(1, I[0])) print('inf' if dp[-1] == v_max else I[-1])