#include #include #include #include #include #include #include #include using namespace std; int main(){ int n; cin >> n; vector v(n), w(n); for(int i = 0; i < n; i++){ scanf("%d %d", &v[i], &w[i]); } int mx_v; cin >> mx_v; int dp[100010]; for(int i = 0; i < 100010; i++)dp[i] = -1; bool over = false; dp[0] = 0; int cnt = 0; for(int i = 0; i < n; i++){ for(int j = 100000; j >= 0; j--){ if(dp[j] >= 0){ if(dp[j] + v[i] > mx_v) over = true; else if(dp[j] + w[i] <= mx_v){ dp[j + w[i]] = dp[j] + v[i]; } } } } int tmp = 0; int mn = 1e9; int mx = -1; bool check = false; for(int i = 1; i <= mx_v; i++){ if(dp[i] == -1)dp[i] = tmp; else tmp = dp[i]; if(dp[i] == mx_v){ check = true; mn = min(i, mn); mx = max(i, mx); } } if(check) { cout << mn << endl; cout << mx << endl; }else if(!check && over) { cout << 1 << endl; cout << *min_element(v.begin(), v.end()) << endl; }else{ int sum = 0; for(int i = 0; i < n; i++){ sum += w[i]; } cout << sum << endl; cout << "inf" << endl; } }