Your DPS in the game is 1 but HP gives you an unlimited number of n enemies DPS and HP you can destroy an enemy in one second. Your DPS hp when you output all the living enemies will hit you to kill all enemies when you drop the least HP
Start thinking wrong sort of time first deal with DPS higher then WA
Even in the game this is very silly.
Should deal with dps/hp higher if put in the game should be first kill the output ability weak ...
If the direct return A.DPS/A.HP>B.DPS/B.HP will appear decimal
So use return A.DPS*B.HP>B.DPS*A.HP
#include <stdio.h> #include <string.h> #include <algorithm> #include <map> #include <math.h >using namespace Std;struct node{ long Long int dps; Long long int hp;}; Node A[25];int CMP (node A,node b) { return a.dps*b.hp>b.dps*a.hp;} int main () {int n;while (~scanf ("%d", &n)) { long long int sum=0; for (int i=1;i<=n;i++) { scanf ("%i64d%i64d", &a[i].dps,&a[i].hp); Sum+=a[i].dps; } Sort (a+1,a+1+n,cmp); Long long int ans=0; for (int i=1;i<=n;i++) { ans+=sum*a[i].hp; Sum-=a[i].dps; } printf ("%i64d\n", ans);}}
HDU 4310 Greed