#include int n; int v; int max_w = 100000; int min_cap = -1; int main() { int num_payload; int k = 0; int x = 0; std::cin >> n; int dp[n+1][100001]; int values[n]; int weights[n]; for (int i = 0; i < n; i++) { std::cin >> values[i] >> weights[i]; k += values[i]; x += weights[i]; } std::cin >> v; if (v >= k) { std::cout << x << std::endl; std::cout << "inf" << std::endl; return 0; } for (int i = 0; i <= x; i++) { dp[0][i] = 0; } for (int i = 1; i <= n; i++) { for (int p = 0; p <= x; p++) { if (p >= weights[i-1]) { dp[i][p] = std::max(dp[i-1][p-weights[i-1]] + values[i-1], dp[i-1][p]); if (dp[i][p] == v) { if (min_cap == -1) { min_cap = p; num_payload = i; } } } else { dp[i][p] = dp[i-1][p]; } } } for (int r = num_payload; r <= n; r++) { for (int i = min_cap; i <= x; i++) { if (dp[num_payload][i] > v) { std::cout << min_cap << std::endl << i - 1 << std::endl; return 0; } } } }