#P465. 【例84.2】分香蕉
【例84.2】分香蕉
Description
It's harvest season again, and bananas have ripened on Flower Fruit Mountain, each with a mass of . Garlic Head has monkeys, each with a weight of . The monkeys eat bananas in a specific order, taking bananas one by one according to their weight from largest to smallest. When one round is complete, if there are still bananas left, they will continue taking them one by one until all bananas are gone. Each monkey is very smart and will choose the banana with the largest mass each time.
Now the question is: what is the total mass of bananas each monkey will receive in the end?
Input Format
The first line contains two integers , ().
The second line contains integers (), representing the mass of each banana.
The third line contains integers (), representing the weight of each monkey, guaranteed to be unique.
Output Format
A single line containing space-separated integers, representing the total mass of bananas each monkey receives.
Sample
5 3
1 2 3 4 5
3 2 17 5 3