#include using namespace std; int N, V, W = 0; int MIN = INT_MAX, MAX = 0; int value[100001] = {0}; int weight[100001] = {0}; int dp[100001] = {0}; void rec(int val = 0, int wei = 0, int count = 0){ dp[wei] = val; if(count == N) return; rec(val + value[count], wei + weight[count], count + 1); rec(val, wei, count + 1); return ; } int main(void){ cin >> N; for(int i = 0; i < N; ++i){ cin >> value[i]; cin >> weight[i]; W += weight[i]; } cin >> V; rec(); for(int i = 1; i <= W; ++i){ if(dp[i] <= dp[i - 1]) dp[i] = dp[i - 1]; if(dp[i] == V){ if(MIN > i) MIN = i; if(MAX < i) MAX = i; } } if(dp[MAX + 1] == 0) cout << MIN << endl << "inf" << endl; else cout << MIN << endl << MAX << endl; return 0; }