#include #include #include #include #include #include #include #include #include #include #include #include #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; using ll = long long; using P = pair; const ll INF = 1e18; ll dp[2005][2005]; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int n; cin >> n; vector

p(n); for(int i = 0; i < n; i++){ int a, b; cin >> a >> b; p[i] = P(b, a); } // bの降順にしたい sort(p.begin(), p.end(), greater

()); vector a, b; for(auto [x, y]: p){ a.push_back(y); b.push_back(x); } for(int i = 0; i <= n; i++){ for(int j = 0; j <= n; j++){ dp[i][j] = INF; } } dp[0][0] = 0; for(int i = 0; i < n; i++){ for(int j = 0; j <= i; j++){ // 普通に買う chmin(dp[i+1][j], dp[i][j]+a[i]+b[i]*(i-j)); // ただで買う chmin(dp[i+1][j+1], dp[i][j]); } } int x = 0, y = 0; int rem = n; for(int i = 0; i < n; i++){ if(i%2 == 0){ rem--; x++; }else{ rem--; x++; if(rem > 0){ rem--; y++; } } if(rem == 0) break; } cout << dp[n][y] << endl; }