现在的位置: 首页 > 综合 > 正文

1634: [Usaco2007 Jan]Protecting the Flowers 护花

2018年01月13日 ⁄ 综合 ⁄ 共 495字 ⁄ 字号 评论关闭
#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;
}

抱歉!评论已关闭.