#include #include #include using namespace std; int v[110], w[110]; int dp[110][100010]; pair solve(int n, int V, pairP) { P = make_pair(1000000, 0); for (int i = 1; i <= n; i++) { for (int j = 1; j <= 100001; j++) { if (j < w[i]) dp[i][j] = dp[i - 1][j]; else dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i]] + v[i]); if (dp[i][j] == V) { P.first = min(P.first, j); P.second = max(P.second, j); } } } return P; } int main() { int n, V; pair P; cin >> n; for (int i = 1; i <= n; i++) cin >> v[i] >> w[i]; cin >> V; cout << solve(n, V, P).first << endl; if(solve(n, V, P).second != 100001) cout << solve(n, V, P).second << endl; else cout << "inf" << endl; }