显示代码纯文本
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
int tim[100000],des[100000];
double dan[100000];
void swapdouble(double &x,double &y)
{
double temp;
temp=x;
x=y;
y=temp;
}
void swapint(int &x,int &y)
{
int temp;
temp=x;
x=y;
y=temp;
}
void qqsort(int l,int r)
{
int ll,rr;
double temp;
ll=l;
rr=r;
temp=dan[rand()%(r-l+1)+l];
while (ll<=rr)
{
while (dan[ll]>temp)
ll++;
while (temp>dan[rr])
rr--;
if (ll<=rr)
{
swapdouble(dan[ll],dan[rr]);
swapint(tim[ll],tim[rr]);
swapint(des[ll],des[rr]);
ll++;
rr--;
}
}
if (l<rr)
qqsort(l,rr);
if (ll<r)
qqsort(ll,r);
}
int main(void)
{
freopen("flowers.in","r",stdin);
freopen("flowers.out","w",stdout);
int i,n,speed=0;
long long total=0;
scanf("%d\n",&n);
for (i=0;i<n;i++)
{
scanf("%d %d\n",&tim[i],&des[i]);
dan[i]=double(des[i])/tim[i];
speed+=des[i];
}
qqsort(0,n-1);
for (i=0;i<n;i++)
{
speed-=des[i];
total+=speed*tim[i]*2;
}
cout<<total<<endl;
fclose(stdin);
fclose(stdout);
return(0);
}