There are $n$ players in your team and for every player you know health and damage, say for $i$th player is $h_i$ and $dmg_i$. Given two types of spells:
$1$: Doubles health of one player, i.e., $h_1 := 2 h_1$
$2$: Assigns value of health of the creature to its damage, i.e., $dmg_i := hp_i$
For any game given $n,$number of spells of type $1$ and type $2$(say $a$ and $b$ respectively) and health($h_1,h_2,\cdots,h_n$) and damage($dmg_1,dmg_2,\cdots,dmg_n$).
To find: Maximal possible sum of damages after using all the spells.
Also, Spell can be used on a certain creature multiple times. Spells can be used in arbitrary order. It isn't necessary to use all the spells.
My strategy:
Using all spells of type $1$ on a single player is more efficient.
Say two players $i,j$ having health $h_i,h_j$ repectively.
For $i \neq j$, say optimal solution is
$h_i' = h_i*2^x$
$h_j' = h_j*2^{a-x}$
say $h_i \geq h_j$
$\implies h_i*2^{x+1} +h_j*2^{a-x-1} \geq h_i*2^x + h_j * 2^{a-x}$
Now, I just sorted the $h_i*2^a - dmg_i $ and if $(b\geq 1)$ replaced $dmg_i$ with the max difference from the sorted list[Here one spell of type $2$ is used]. And for rest of the spells of type $2$ i just sort the new list $h_i - dmg_i$ and used spells till either no spells left for $h_i - dmg_i \geq 1$
But I am doing something wrong and i didn't figure out what. Any help will be appreciated!
Thanks
Edit:
As pointed out by @RideTheWavelet, I am now using spell of type $1$ only if it can increase damage ($h_i*2^a - dmg_i > 0$ then only i use spell of type $1$)
But there is some more mistake in my method.
Consider $h_{i}=1$ for all $i,$ $a\leq 9,$ $b=$anything, and $dmg_i=1024$ for all $i$. Then the best strategy is clearly not to use any spells (unless boosting health is otherwise useful, in which case the available Type I spell should be used).