#include using namespace std; #define ALL(x) (x).begin(), (x).end() #define REP(i,n) for(int i=0; ib ? a=b, true : false; } using ll=long long; const int INF=1e9+10; const ll INFL=4e18; #ifdef DEBUG #include "./debug.hpp" #else #define debug(...) #define print_line #endif //---------------------------------------------------------- void solve() { ll N; cin>>N; vector A(N), B(N); REP(i,N) cin>>A[i]>>B[i]; vector dp(N+1,0), ndp=dp; dp[0]=0; REP(i,N) { fill(ALL(ndp),-INFL); for(int j=0; j<=N-i; j++) { chmax(ndp[j],dp[j]+A[i]*j); if(j>0) chmax(ndp[j-1],dp[j]+B[i]); } swap(dp,ndp); } cout<>T; while(T--) solve(); }