2838. Maximum Coins Heroes Can Collect
There is a battle and
n
heroes are trying to defeatm
monsters. You are given two 1-indexed arrays of positive integersheroes
andmonsters
of lengthn
andm
, respectively.heroes[i]
is the power ofith
hero, andmonsters[i]
is the power ofith
monster.The
ith
hero can defeat thejth
monster ifmonsters[j] <= heroes[i]
.You are also given a 1-indexed array
coins
of lengthm
consisting of positive integers.coins[i]
is the number of coins that each hero earns after defeating theith
monster.Return an array
ans
of lengthn
whereans[i]
is the maximum number of coins that theith
hero can collect from this battle.Notes
- The health of a hero doesn’t get reduced after defeating a monster.
- Multiple heroes can defeat a monster, but each monster can be defeated by a given hero only once.
1 | class Solution { |