n=int(input())
m=[list(map(int,input().split())) for i in range(n)]
maxw=0
for i in range(n):
    maxw += m[i][1]
v = int(input())
dp=[[-1]*(maxw+1) for i in range(n+1)]
dp[0][0] = 0

for i in range(n):
    for j in range(maxw+1):
        if dp[i%2][j] == -1:
            continue
        dp[(i+1)%2][j] = max(dp[(i+1)%2][j],dp[i%2][j])
        if j + m[i][1] <= len(dp[0])-1:
            dp[(i+1)%2][j+m[i][1]] = max(dp[(i+1)%2][j+m[i][1]],dp[i%2][j] + m[i][0])

ans=[]
for i in range(maxw+1):
    if dp[n%2][i] == v:
        while dp[n%2][i] <= v:
            ans.append(i)
            i+=1
            if i >= maxw+1:
                break
# print(dp[n%2])
                
if dp[n%2][-1] == v:
    print(maxw)
    print('inf')
else:
    print(1 if ans[0] == 0 else ans[0]  )
    print(ans[-1])