This file contains 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; | |
} |
沒有留言:
張貼留言