n = int(input()) V = [] W = [] for i in range(n): v, w = map(int, input().split()) V.append(v) W.append(w) u = int(input()) if u == 0: print(1) print(min(W)-1) exit() INF = 10**18 dp = [INF]*(u+2) dp[0] = 0 for v, w in zip(V, W): for i in reversed(range(u+2)): if i+v <= u+1: dp[i+v] = min(dp[i+v], dp[i]+w) for i in reversed(range(u+1)): dp[i] = min(dp[i], dp[i+1]) if dp[u+1] != INF: print(dp[u]) print(dp[u+1]-1) else: print(dp[u]) print('inf')