一种比较常见的排序方式,详情可看:【1月18日 牛客每日一题】

#include <bits/stdc++.h>
#define il inline
#define double long double
using namespace std;
using ll = long long;
using ull = unsigned long long;
using int128 = __int128_t;

const ll N = 2e5 + 5, mod = 1e9+7, inf = 2e18;
const double eps = 1e-9;
double PI = 3.1415926;

il void solve(){
    int n;
    cin>>n;
    struct Node{
        ll t,d;
        bool operator<(const Node&a)const{
            return d*a.t>a.d*t;
        }
    };
    ll sum=0;
    vector<Node>a(n);
    for(auto &[x,y]:a){
        cin>>x>>y;
        sum+=y;
    }
    sort(a.begin(),a.end());
    ll ans=0;
    for(auto [t,d]:a){
        sum-=d;
        ans+=2*t*sum;
    }
    cout<<ans;
}

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

    int t = 1;

    // cin >> t;

    while (t--){

        solve();
    }

    return 0;
}