using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray(); public static void Main() { Solve(); } static void Solve() { var n = NN; var map = NArr(n); WriteLine(Blocks(n, map)); } static int Blocks(int n, int[][] map) { Array.Sort(map, (l, r) => (l[0] + l[1]).CompareTo(r[0] + r[1])); var dp = new long[n + 1][]; for (var i = 0; i < dp.Length; ++i) dp[i] = Enumerable.Repeat(long.MaxValue / 2, n + 1).ToArray(); dp[0][0] = 0; for (var i = 0; i < n; ++i) { for (var j = 0; j < n; ++j) { dp[i + 1][j] = Math.Min(dp[i + 1][j], dp[i][j]); if (dp[i][j] <= map[i][1]) dp[i + 1][j + 1] = Math.Min(dp[i + 1][j + 1], dp[i][j] + map[i][0]); } } var ans = 0; for (var i = 0; i <= n; ++i) if (dp[n][i] < long.MaxValue / 2) ans = i; return ans; } }