#include #include #include using namespace std; typedef long long ll; int main(){ int n; scanf("%d", &n); vector> v; int a, b; for(int i = 0; i < n; i++){ scanf("%d %d", &a, &b); v.push_back(make_pair(a,b)); } sort(v.rbegin(), v.rend(), [](pair p, pair q){return p.second < q.second;}); int buy = n/3*2 + n%3; vector dp(buy, 1ll<<60); for(int i = 0; i < n; i++){ for(int j = buy-1; j > 0; j--){ dp[j] = min(dp[j], dp[j-1]+v[i].first+(ll)v[i].second*j); } dp[0] = min(dp[0], (ll)v[i].first); } printf("%ld\n", dp[buy-1]); return 0; }