#include using namespace std; #define FOR(i, n) for(int i = 0; i < (n); i++) #define MEM(a, x) memset(a, x, sizeof(a)) #define ALL(a) a.begin(), a.end() #define UNIQUE(a) a.erase(unique(ALL(a)), a.end()) typedef long long ll; typedef pair P; int n, V, dp[100005]; int main(int argc, char const *argv[]) { ios_base::sync_with_stdio(false); cin >> n; vector

vw(n); FOR(i, n) cin >> vw[i].first >> vw[i].second; cin >> V; FOR(i, n) { vector _dp(V+2); FOR(j, V+2) { if (j-vw[i].first >= 0) _dp[j] = max(dp[j], dp[j-vw[i].first] + vw[i].second); else _dp[j] = dp[j]; } FOR(j, V+2) dp[j] = _dp[j]; } cout << dp[V] << endl; if (dp[V+1] == dp[V]) cout << "inf" << endl; else cout << dp[V+1]-1 << endl; return 0; }