用排序加枚举,吸了一口氧气,复杂度O^2也能过
#include<bits/stdc++.h>
using namespace std;
int n;
struct C{
int x,v;
}c[50005];
bool cmp(C a,C b){
return a.v<b.v;
}
unsigned long long res=0;
int main(){
cin>>n;
for(int i=1;i<=n;i++) cin>>c[i].v>>c[i].x;
sort(c+1,c+1+n,cmp);
for(int i=1;i<=n;i++){
unsigned long long tmp=0;
for(int j=1;j<i;j++){
tmp+=abs(c[i].x-c[j].x);
}
res+=tmp*c[i].v;
}
cout<<res;
return 0;
}