Archive / 2023 / Selection Test
Sweet Fruits
Azusa brought ๐ different types of exotic fruits to the Fruit Lovers Club. They are numbered from 1 to ๐, where the ๐-th fruit has a sweetness level described by an integer ๐๐.
Mio loves trying new fruits, but for health reasons, she can taste at most ๐ fruits each day.
Days are 1-indexed (numbered 1,2,3,โฆ). Tasting the fruit ๐ on the ๐-th day will cause a sweetness penalty of (๐โ ๐๐), as fruits become sweeter with time. Each fruit can be tasted at most once.
The total sweetness penalty will be the sum of the individual penalties of each fruit tasted.
Suppose that Mio chooses exactly ๐ fruits and tastes them in any order she wants. What is the minimum total sweetness penalty she can get?
Since Mio is an adventurous fruit enthusiast, she wants you to answer this question for every value of ๐ between 1 and ๐.
Input Format
The first line contains two integers ๐ and ๐.
The second line contains ๐ integers ๐1,๐2,โฆ,๐๐.
Output Format
You have to output ๐ integers ๐ฅ1,๐ฅ2,โฆ,๐ฅ๐ on a single line, separed by spaces, where ๐ฅ๐ is the minimum total sugar penalty Mio can get if she eats exactly ๐ fruits.
Constraints
(1โค๐โค๐โค200 000)
(1โค๐๐โค200 000)
Sample Input 0
9 2
6 19 3 4 4 2 6 7 8
Sample Output 0
2 5 11 18 30 43 62 83 121
Open on HackerRank โ ยท Markdown source ยท Back to the archive