Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
If a hero can defeat the <code>i<sup>th</sup></code> monster, then he defeats all the monsters having a power less than <code>monster[i]</code>.
Sort monsters by their powers. Also change the order of the coins array according to this sort.
Construct a prefix sum array for the updated coins array.
For each hero, do a binary search and find the last position of the most powerful monster that this hero can defeat.
If said monster has index <code>i</code>, then the <code>i<sup>th</sup></code> element of the partial sum array would be the answer.