您的位置:首页 > 其它

1634: [Usaco2007 Jan]Protecting the Flowers 护花

2014-05-31 12:10 411 查看
#include<algorithm>
#include<iostream>
#include<cstdio>
using namespace std;
struct data{int x,y;}a[100001];
inline int read(){
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x*=10;x+=ch-'0';ch=getchar();}
return x*f;
}
inline bool cmp(data a,data b){return a.x*b.y<b.x*a.y;}
int n;
long long ans,t;
int main(){
n=read();
for(int i=1;i<=n;i++){
a[i].x=read();a[i].y=read();
}
sort(a+1,a+n+1,cmp);
for(int i=1;i<=n;i++){
ans+=t*a[i].y;
t+=a[i].x*2;
}
printf("%lld",ans);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: