#include using namespace std; typedef long long ll; int dp[110][100010]; int main() { cin.tie(0); ios::sync_with_stdio(false); int N, V; cin >> N; const int INF = 1 << 28; fill((int*)begin(dp), (int*)end(dp), -INF); dp[0][0] = 0; for(int i = 0; i < N; i++) { int v, w; cin >> v >> w; for(int j = 0; j <= 100000; j++) { if(dp[i][j] == -INF) continue; dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]); dp[i + 1][j + w] = max(dp[i + 1][j + w], dp[i][j] + v); } } cin >> V; int minW = INF, maxW = 0; int v = 0; for(int j = 1; j <= 100000; j++) { v = max(v, dp[N][j]); if(v == V) { minW = min(minW, j); maxW = max(maxW, j); } } cout << minW << endl; if(maxW == 100000) cout << "inf" << endl; else cout << maxW << endl; }