#include "bits/stdc++.h" using namespace std; #define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i)) #define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i)) #define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i)) static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL; typedef vector vi; typedef pair pii; typedef vector > vpii; typedef long long ll; template static void amin(T &x, U y) { if (y < x) x = y; } template static void amax(T &x, U y) { if (x < y) x = y; } int main() { int N; while (~scanf("%d", &N)) { int X = N * 1000 + 1; vector dp(X + 1, 0); rep(i, N) { int v; int w; scanf("%d%d", &v, &w); for (int j = X - w; j >= 0; -- j) { amax(dp[j + w], dp[j] + v); } } int V; scanf("%d", &V); pii ans(INF, -INF); rer(i, 1, X) if(dp[i] == V) { amin(ans.first, i); amax(ans.second, i); } printf("%d\n", ans.first); if (ans.second == X) puts("inf"); else printf("%d\n", ans.second); } return 0; }