#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; using P = pair; constexpr int INF = 1001001001; constexpr int mod = 1000000007; // constexpr int mod = 998244353; template inline bool chmax(T& x, T y){ if(x < y){ x = y; return true; } return false; } template inline bool chmin(T& x, T y){ if(x > y){ x = y; return true; } return false; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int n, V; cin >> n; vector v(n), w(n); for(int i = 0; i < n; ++i) cin >> v[i] >> w[i]; cin >> V; int MAX = 1000 * n; vector dp(MAX + 1003), dp2(MAX + 1003); for(int i = 0; i < n; ++i){ dp2 = dp; for(int j = 0; j <= MAX; ++j){ chmax(dp2[j + w[i]], dp[j] + v[i]); } swap(dp, dp2); } int minans = -1, maxans = -1; for(int i = 1; i <= MAX + 1; ++i){ if(dp[i] == V){ maxans = i; if(minans == -1) minans = i; } } cout << minans << '\n'; if(maxans == MAX + 1) cout << "inf\n"; else cout << maxans << '\n'; return 0; }