贪心

如果一头牛的破坏力越强,迁到牛棚的时间越少,我们去迁走它那么损失越小,我们按去排序,防止被卡精度,我们对两个牛排序的时候去比较,这边贴代码

/*

##     ##   #######   ########    ###     ########  ##   ##
##     ##  ##     ##     ##      ## ##    ##    ##  ##   ##
##     ##  ##     ##     ##     ##   ##   ##    ##  ##   ##
#########  ##     ##     ##    ##     ##  ########  ##   ##
##     ##  ##     ##     ##    #########  ##  ##    ##   ##
##     ##  ##     ##     ##    ##     ##  ##   ##   ##   ##
##     ##   #######      ##    ##     ##  ##    ##   #####

*/
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(0),cout.tie(0)
#define int long long
#define endl '\n'
#define rep(i,a,b) for(int i = a ; i <= b ; i++)
#define per(i,a,b) for(int i = a ; i >= b ; i--)
using namespace std;
void solve() {
    int n;
    cin >> n;
    vector<pair<int,int>> arr(n);
    rep(i,0,n-1)cin >> arr[i].first >> arr[i].second;
    sort(arr.begin(),arr.end(),[](const pair<int,int>& a,const pair<int,int>& b) {
        return b.first * a.second < a.first * b.second;
    });
    vector<int> prefix(n+1);
    rep(i,1,n)prefix[i] = prefix[i-1] + arr[i-1].second;
    int ans = 0;
    per(i,n-1,0) {
        ans += arr[i].first * 2 * prefix[i];
    }
    cout << ans << endl;
}
signed main() {
    IOS;
  	int T = 1;
  	// cin >> T;
  	while (T--) {
    	solve();
  	}
    return 0;
}