import sys; input = sys.stdin.buffer.readline sys.setrecursionlimit(10**7) from collections import defaultdict con = 10 ** 9 + 7; INF = float("inf") def getlist(): return list(map(int, input().split())) #処理内容 def main(): N = int(input()) DP = [[-INF for i in range(100001)] for j in range(N + 1)] DP[0][0] = 0 for i in range(N): v, w = getlist() for j in range(100001): if DP[i][j] != -INF: DP[i + 1][j] = max(DP[i][j], DP[i + 1][j]) DP[i + 1][j + w] = max(DP[i + 1][j + w], DP[i][j] + v) V = int(input()) m = INF M = INF for i in range(100001): if DP[-1][i] >= V: m = min(m, i) if DP[-1][i] > V and M == INF: M = i - 1 m = max(1, m) if M == INF: M = "inf" print(m) print(M) if __name__ == '__main__': main()