#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include 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; } constexpr long long MAX = 5100000; constexpr long long INF = 1LL << 60; constexpr int inf = 1000000007; //constexpr long long mod = 1000000007LL; constexpr long long mod = 998244353LL; using namespace std; typedef unsigned long long ull; typedef long long ll; struct Product { ll a, b; Product(ll _a, ll _b) :a(_a), b(_b) {} bool operator<(const Product& p) const { return b > p.b; } }; int main() { /* cin.tie(nullptr); ios::sync_with_stdio(false); */ ll n; scanf("%lld", &n); vector> dp(n + 1, vector(n + 1, INF)); dp[0][0] = 0; vector vp; vp.reserve(n); for (int i = 0; i < n; i++) { ll a, b; scanf("%lld %lld", &a, &b); vp.emplace_back(a, b); } sort(vp.begin(), vp.end()); for (int i = 0; i < n; i++) { for (int j = 0; j <= min(n / 3, i); j++) { chmin(dp[i + 1][j + 1], dp[i][j]); chmin(dp[i + 1][j], dp[i][j] + vp[i].a + vp[i].b * (i - j)); } } cout << dp[n][n / 3] << endl; return 0; }