#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; #define fst first #define snd second /* clang-format off */ template struct _vec { using type = vector::type>; }; template struct _vec { using type = T; }; template using vec = typename _vec::type; template vector make_v(size_t size, const T& init) { return vector(size, init); } template auto make_v(size_t size, Ts... rest) { return vector(size, make_v(rest...)); } template inline void chmin(T &a, const T& b) { if (b < a) a = b; } template inline void chmax(T &a, const T& b) { if (b > a) a = b; } /* clang-format on */ using P = pair; const ll INF = 1ll << 60; int main() { #ifdef DEBUG ifstream cin("in.txt"); #endif int N; while (cin >> N) { vector

ps(N); for (auto& p : ps) cin >> p.snd >> p.fst; sort(ps.rbegin(), ps.rend()); int M = N / 3; vector dp(M + 2, INF); dp[0] = 0; for (int i = 0; i < N; i++) { vector ndp(M + 2, INF); for (int j = 0; j <= i && j <= M; j++) { chmin(ndp[j + 1], dp[j]); chmin(ndp[j], dp[j] + (i - j) * ps[i].fst + ps[i].snd); } dp.swap(ndp); } cout << dp[M] << endl; } return 0; }