1 #include<iostream> 2 #include<algorithm> 3 #include<cstring> 4 #include<cstdio> 5 using namespace std; 6 const int maxn=2010; 7 struct node 8 { 9 int a,b; 10 }gua[maxn]; 11 int dp[maxn][maxn]; 12 int n; 13 bool cmp(node a,node b) 14 { 15 return a.a>b.a; 16 } 17 int main() 18 { 19 cin>>n; 20 for(int i=1;i<=n;i++) 21 { 22 cin>>gua[i].a>>gua[i].b; 23 } 24 sort(gua+1,gua+1+n,cmp); 25 memset(dp,-0x3f,sizeof(dp)); 26 dp[0][1]=0; 27 for(int i=1;i<=n;i++) 28 { 29 for(int j=0;j<=n;j++) 30 { 31 dp[i][j]=max(dp[i-1][j],dp[i-1][max(j-gua[i].a,0)+1]+gua[i].b); 32 } 33 } 34 int ans=-999999999; 35 for(int i=0;i<=n;i++) 36 { 37 ans=max(ans,dp[n][i]); 38 } 39 cout<<ans<<endl; 40 return 0; 41 }