Created
January 2, 2014 06:44
-
-
Save KT-Yeh/8215782 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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