BZOJ 1634 护花

Posted on 2016-09-21 19:27  ziliuziliu  阅读(112)  评论(0编辑  收藏  举报

d/t从大到小排序。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 100500
using namespace std;
long long n,ans=0;
struct pnt
{
    long long d,t,id;
}p[maxn];
bool cmp(pnt x,pnt y)
{
    return (double)x.d/x.t>(double)y.d/y.t;
}
int main()
{
    scanf("%lld",&n);
    for (long long i=1;i<=n;i++)
    {
        scanf("%lld%lld",&p[i].t,&p[i].d);
        p[i].id=i;
    }    
    sort(p+1,p+n+1,cmp);
    long long t=0;
    for (long long i=1;i<=n;i++)
    {
        ans+=t*p[i].d;
        t+=2*p[i].t;
    }
    printf("%lld\n",ans);
    return 0;
}