#include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; vector V(N), W(N); for (int i = 0; i < N; i++) { cin >> V[i] >> W[i]; } int X; cin >> X; vector> dp(N + 1, vector((N + 1) * *max_element(W.begin(), W.end()) + 1, 0)); for (int i = 0; i < N; i++) { for (int w = 0; w < (int)dp[0].size(); w++) { dp[i + 1][w] = max(dp[i + 1][w], dp[i][w]); if (w + W[i] < (int)dp[0].size()) dp[i + 1][w + W[i]] = max(dp[i + 1][w + W[i]], dp[i][w] + V[i]); } } vector res; for (int w = 1; w < (int)dp[0].size(); w++) { if (dp[N][w] == X) res.emplace_back(w); } cout << res.front() << '\n'; int tot = 0; for (int v : V) { tot += v; } if (tot == X) { cout << "inf" << '\n'; } else { cout << res.back() << '\n'; } return 0; }