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