#include "bits/stdc++.h" #define MOD 1000000007 #define rep(i, n) for(ll i=0; i < (n); i++) #define rrep(i, n) for(ll i=(n)-1; i >=0; i--) #define ALL(v) v.begin(),v.end() #define rALL(v) v.rbegin(),v.rend() #define FOR(i, j, k) for(ll i=j;i llvec; typedef vector dvec; typedef pair P; typedef long double ld; struct edge{ll x, c;}; /************************************** ** A main function starts from here ** ***************************************/ int main(){ ll N; cin >> N; llvec v(N); llvec w(N); rep(i, N){ cin >> v[i] >> w[i]; } ll V; cin >> V; ll M = 100001; vector dp(N+1, llvec(M+1, 0)); rep(i, N){ rep(j, M+1){ dp[i+1][j] = max(dp[i][j], dp[i+1][j]); if(j+w[i]<=M){ dp[i+1][j+w[i]] = max(dp[i][j] + v[i], dp[i+1][j+w[i]]); } } } ll ans1=1e18, ans2=0; rep(i, M){ if(dp[N][i+1]==V){ ans1 = min(ans1, i+1); ans2 = max(ans2, i+1); } } if(ans2<=1e5){ cout << ans1 << endl << ans2 << endl; }else{ cout << ans1 << endl << "inf" << endl; } return 0; }