#include #include int W = 100000; void solve() { std::vector dp(W + 1, 0); int n; std::cin >> n; while (n--) { int v, w; std::cin >> v >> w; for (int x = W; x >= w; --x) { dp[x] = std::max(dp[x], dp[x - w] + v); } } int min = W, max = 0; int v; std::cin >> v; for (int w = 1; w <= W; ++w) { if (dp[w] != v) continue; min = std::min(min, w); max = std::max(max, w); } std::cout << min << "\n"; if (max == W) { std::cout << "inf\n"; } else { std::cout << max << "\n"; } } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }