Hdu4310(贪心)
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn = 20 + 5;
struct Hero {
int hp;
int dps;
}hero[maxn];
int cmp(Hero a, Hero b){
return a.hp * b.dps < b.hp * a.dps ; //比率排序
}
int main(){
int n;
while(cin>>n){
int sum = 0;
for(int i=0; i<n; i++){
cin>>hero[i].dps >> hero[i].hp ;
sum += hero[i].dps ;
}
sort(hero, hero + n, cmp);
int ans = 0;
for(int i=0; i<n; i++){
for(int j=0; j<hero[i].hp; j++){
ans += sum;
}
sum -= hero[i].dps ;
}
cout<<ans<<endl;
}
return 0;
}