#include #include #include #include #include #include #include #define rep(i, n) for (int i = 0; i < (n); i++) using ll = long long int; using namespace std; int N, V; int v[1010], w[1010]; int dp[110][100010]; int main() { cin >> N; rep(i, N) { cin >> v[i] >> w[i]; } cin >> V; memset(dp, 0, sizeof(dp)); for(int i = 0; i < N; i++) { for(int j = 0; j < 100002; j++) { dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]); dp[i + 1][j + w[i]] = max(dp[i + 1][j + w[i]], dp[i][j] + v[i]); } } int mi = 100001; int ma = -1; for(int i = 1; i < 100002; i++) { if(dp[N][i] == V) { mi = min(mi, i); ma = max(ma, i); } } cout << mi << endl; if(ma == 100001) cout << "inf" << endl; else cout << ma << endl; }