#include using namespace std; int N, V, v[109], w[109], dp[109][120009]; int main() { cin >> N; for(int i = 0; i < N; i++) cin >> v[i] >> w[i]; cin >> V; for(int i = 0; i < N; i++) { for(int j = 0; j <= 120000; j++) { dp[i + 1][j] = dp[i][j]; if(j >= w[i]) dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - w[i]] + v[i]); } } vector ret; for(int i = 0; i <= 120000; i++) { if(dp[N][i] == V) ret.push_back(i); } cout << ret.front() << endl << (ret.back() == 120000 ? "inf" : to_string(ret.back())) << endl; return 0; }