import java.lang.reflect.Array; import java.util.Arrays; import java.util.Scanner; public class Yuki054 { public static void main(String[] args) { Yuki054 hoge = new Yuki054(); } Yuki054() { Scanner scanner = new Scanner(System.in); int N = scanner.nextInt(); int[] datas = new int[N]; for (int i = 0; i < N; i++) { int V = scanner.nextInt(); int T = scanner.nextInt(); datas[i] = T * 20000 + V; } Arrays.sort(datas); int[] dp = new int[100001]; Arrays.fill(dp, -1); dp[0] = 0; for (int i = 0; i < N; i++) { int V = datas[i] % 20000; int T = datas[i] / 20000; for (int j = T - 1; j >= 0; j--) { if (dp[j] != -1) { int K = Math.min(j + V, 10000); dp[K] = Math.max(dp[K], dp[j] + V); } } } Arrays.sort(dp); System.out.println(dp[dp.length - 1]); } }