monsters array and the heroes array in ascending order.prefix_sum array where prefix_sum[i] represents the total number of coins that can be earned by defeating the first i monsters.ans to store the maximum coins each hero can collect.prefix_sum array and assign the value to the corresponding index in ans.ans array.