#include using ull = unsigned long long; ull n; ull v; ull max_w = 100000; ull min_cap = -1; ull equal_weight = -1; int main() { ull num_payload; ull k = 0; ull x = 0; std::cin >> n; ull dp[n+1][100001]; ull values[n]; ull weights[n]; for (ull 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 (ull i = 0; i <= x; i++) { dp[0][i] = 0; } for (ull i = 1; i <= n; i++) { for (ull 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]; } } } if (min_cap == -1) { min_cap = 1; num_payload = 1; } for (ull r = num_payload; r <= n; r++) { for (ull i = min_cap; i <=x; i++) { if (dp[r][i] > v) { std::cout << min_cap << std::endl << i - 1 << std::endl; return 0; } } } }