代码:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
using namespace std;
const int N=100006;
long long sum=0;
int n;
struct node
{
long long time;
long long cost;
double worth;
};
node a[N];
bool comp(node a,node b)
{
if (a.worth!=b.worth)
return a.worth>b.worth;
}
int main()
{
//freopen("1.txt","r",stdin);
scanf("%d",&n);
for (int i=1;i<=n;i++)
{
double square;
scanf("%d%d",&a[i].time,&a[i].cost);
square=a[i].time*2;
double value=a[i].cost;
a[i].worth=1.0*a[i].cost/square;
}
sort(a+1,a+1+n,comp);
for (int i=1;i<=n;i++)
{
for (int j=i+1;j<=n;j++)
{
sum+=a[j].cost*2*a[i].time;
}
}
printf("%lld",sum);
return 0;
}
求大佬帮助,改了半天了