#include using namespace std; typedef long long ll; typedef long double ld; #define REP(i, n) for (int i = 0; i < (n); ++i) #define REPR(i, n) for (int i = n - 1; i >= 0; --i) #define FOR(i, m, n) for (ll i = m; i < n; ++i) #define FORR(i, m, n) for (ll i = m; i >= n; --i) #define ALL(v) (v).begin(),(v).end() templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b> n; vector a(n),b(n); vector> p(n); REP(i,n){ cin >> a[i] >> b[i]; p[i]={b[i],a[i]}; } sort(ALL(p)); reverse(ALL(p)); REP(i,n){ a[i]=p[i].second; b[i]=p[i].first; } vector> dp(n+1,vector(n/3+2,INF)); dp[0][0]=0; REP(i,n){ REP(j,n/3+1){ if(dp[i][j]==INF){ continue; } chmin(dp[i+1][j],dp[i][j]+a[i]+b[i]*(i-j)); chmin(dp[i+1][j+1],dp[i][j]); } } cout << dp[n][n/3] << endl; }