N=int(input()) X=[list(map(int,input().split())) for i in range(N)] INF=10**15 DP=[[INF]*(N+1) for i in range(N+1)] X.sort(key=lambda x:sum(x)) DP[0][0]=0 for i in range(N): for j in range(i+1): if DP[i][j]<=X[i][1]: DP[i+1][j+1]=min(DP[i+1][j+1],DP[i][j]+X[i][0]) DP[i+1][j]=min(DP[i+1][j],DP[i][j]) for i in range(N,-1,-1): if DP[N][i]