import copy def main(): N = int(input()); INF = float("inf") Z = [] for i in range(N): w,s = map(int,input().split()) Z.append((w,s)) Z.sort(key = lambda x: x[0] + x[1]) #dp[i][j]: i個目まで見てj個使った時の最小の重さ dp = [INF]*(N+1) dp[0] = 0 for i in range(N): p = copy.copy(dp) #i個目を使わないときをコピー p,dp = dp,p w,s = Z[i] for j in range(N): if dp[j] <= s: dp[j+1] = min(dp[j+1], p[j] + w) #print(dp) for j in reversed(range(N+1)): if dp[j] != INF: print(j);exit() if __name__ == '__main__': main()