# フツーの01なっぷさっく N = int(input()) que = [tuple(map(int, input().split())) for i in range(N)] V = int(input()) # dp[X][W] = X番目までの荷物を使って ちょうど重さWで実現できる最大の価値 dp = [[0 for i in range(10**5+1)] for j in range(N+1)] for i in range(N): value, weight = que[i] for j in range(10**5+1): if j >= weight: dp[i+1][j] = max(dp[i+1][j],dp[i][j], dp[i][j-weight]+value) else: dp[i+1][j]=max(dp[i+1][j],dp[i][j]) wanted = dp[N] mini = 1 for i in range(1,10**5+1): if wanted[i] == V: mini = i break maxi = mini for i in range(mini,10**5+1): if wanted[i] == V: maxi = i value_max=0 for value,weight in que: value_max+=value if value_max==wanted[maxi]: maxi="inf" print(mini) print(maxi)