NOI Contest Archive

Archive / 2023 / Selection Test

Sweet Fruits

Medium ยท National Olympiad in Informatics Sri Lanka - Screening Test 2023

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