Skip to content

Instantly share code, notes, and snippets.

@KT-Yeh
Created January 2, 2014 06:44
Show Gist options
  • Save KT-Yeh/8215782 to your computer and use it in GitHub Desktop.
Save KT-Yeh/8215782 to your computer and use it in GitHub Desktop.
#include<cstdio>
#include<algorithm>
using namespace std;
struct cow{
int T;
int D;
};
bool cmp(cow a,cow b)
{
return (a.D*1.0/a.T)>(b.D*1.0/b.T); //*1.0
}
int main()
{
int N,i,j;
long long sum=0,ans=0; //long long int
cow a[100001];
while(scanf("%d",&N)!=EOF){
for (i=0;i<N;i++){
scanf("%d%d",&a[i].T,&a[i].D);
sum+=a[i].D;
}
sort(a,a+N,cmp);
for(i=0;i<N;i++){
sum-=a[i].D;
ans+=(sum*2*a[i].T);
}
printf("%lld\n",ans);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment