6
dp[i][j]:前i项选择j项的最大值
dp[i][j]=max(dp[i-1][j],dp[i][j-1]+p[i].ai-p[i].bi*(j-1))
#include<bits/stdc++.h> //#include<iostream> //#include<cmath> //#include<cstring> //#include<string> //#include<cstdlib> //#include<cstdio> //#include<map> //#include<algorithm> using namespace std; template<class T>inline T read(T&x) { char c; while((c=getchar())<=32); bool ok=false; if(c=='-')ok=true,c=getchar(); for(x=0; c>32; c=getchar()) x=x*10+c-'0'; if(ok)x=-x; return x; } template<class T> inline void read_(T&x,T&y) { read(x); read(y); } template<class T> inline void read__(T&x,T&y,T&z) { read(x); read(y); read(z); } template<class T> inline void write(T x) { if(x<0)putchar('-'),x=-x; if(x<10)putchar(x+'0'); else write(x/10),putchar(x%10+'0'); } template<class T>inline void writeln(T x) { write(x); putchar('\n'); } //-------ZCC IO template------ const int maxn=1001; const double inf=999999999; #define lson (rt<<1),L,M #define rson (rt<<1|1),M+1,R #define M ((L+R)>>1) #define For(i,t,n) for(int i=(t);i<(n);i++) typedef long long LL; typedef double DB; #define bug printf("---\n"); struct node { int ai,bi; bool operator<(node tmp)const { if(tmp.bi!=bi)return bi>tmp.bi; else return ai>tmp.ai; } }p[maxn]; int dp[maxn][maxn]; int main() { int n; while(read(n)) { for(int i=1;i<=n;i++) { read_(p[i].ai,p[i].bi); } sort(p+1,p+n+1); For(i,0,n+1)dp[i][0]=0; For(i,1,n+1)For(j,1,i+1) { dp[i][j]=max(dp[i-1][j],dp[i-1][j-1]+p[i].ai-(j-1)*p[i].bi); } int ans=0; For(i,0,n+1) ans=max(ans,dp[n][i]); writeln(ans); } return 0; }