贪心
因为交换这俩头牛的搬走顺序不会影响其他牛
所以只要排序就好了
下面的
∗.y
表示的是赶走这头牛需要的时间
∗.x
则是这头牛单位时间吃掉的花
当
x.x×y.y>y.x×x.y
时就是牛
x
放在前更优
因为赶走牛
所以应该尽快赶走牛
#include<set>
#include<map>
#include<cmath>
#include<ctime>
#include<queue>
#include<stack>
#include<cstdio>
#include<vector>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define g getchar()
#define ll long long
#define inf 0x3f3f3f3f
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=g;
for(;ch<'0'||ch>'9';ch=g)if(ch=='-')f=-1;
for(;ch>='0'&&ch<='9';ch=g)x=x*10+ch-'0';
return x*f;
}
inline void out(ll x){
int a[25],wei=0;
if(x<0)putchar('-'),x=-x;
for(;x;x/=10)a[++wei]=x%10;
if(wei==0){puts("0");return;}
for(int j=wei;j>=1;--j)putchar('0'+a[j]);
putchar('\n');
}
struct re{int x,y;}d[100001];
int n;
ll ans,t;
bool cmp(re x,re y){
return x.x*y.y>y.x*x.y;
}
int main(){
// freopen("","r",stdin);
// freopen("","w",stdout);
n=read();
for(int i=1;i<=n;++i)
d[i].y=read(),d[i].x=read();
sort(d+1,d+1+n,cmp);
ans=0;t=0;
for(int i=1;i<=n;++i)
ans+=t*d[i].x,t+=d[i].y*2;
out(ans);
return 0;
}