/* -*- coding: utf-8 -*- * * 798.cc: No.798 コレクション - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 100; const int MAX_M = MAX_N / 3; const long long LINF = 1LL << 62; /* typedef */ typedef long long ll; typedef pair pii; /* global variables */ pii bas[MAX_N]; ll dp[MAX_N + 1][MAX_M + 1]; /* subroutines */ inline void setmin(ll &a, ll b) { if (a > b) a = b; } /* main */ int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d%d", &bas[i].second, &bas[i].first); sort(bas, bas + n, greater()); int m = n / 3; for (int i = 0; i <= n; i++) fill(dp[i], dp[i] + m + 1, LINF); dp[0][0] = 0; for (int i = 0; i < n; i++) { int &ai = bas[i].second, &bi = bas[i].first; for (int j = 0; j <= i && j <= m; j++) if (dp[i][j] < LINF) { if (j < m) setmin(dp[i + 1][j + 1], dp[i][j]); setmin(dp[i + 1][j], dp[i][j] + ai + bi * (i - j)); } } printf("%lld\n", dp[n][m]); return 0; }