CF1253C.Sweets Eating

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Tsumugi brought nn delicious sweets to the Light Music Club. They are numbered from 11 to nn, where the ii-th sweet has a sugar concentration described by an integer aia_i.

Yui loves sweets, but she can eat at most mm sweets each day for health reasons.

Days are 11-indexed (numbered 1,2,3,…1, 2, 3, \ldots). Eating the sweet ii at the dd-th day will cause a sugar penalty of (d⋅ai)(d \cdot a_i), as sweets become more sugary with time. A sweet can be eaten at most once.

The total sugar penalty will be the sum of the individual penalties of each sweet eaten.

Suppose that Yui chooses exactly kk sweets, and eats them in any order she wants. What is the minimum total sugar penalty she can get?

Since Yui is an undecided girl, she wants you to answer this question for every value of kk between 11 and nn.

Tsumugi 给轻音部带来了 nn 颗美味的糖果。这些糖果编号为 11 到 nn,其中第 ii 颗糖果的糖分浓度由整数 aia_i 描述。

Yui 喜欢吃糖果,但出于健康原因,她每天最多只能吃 mm 颗糖果。

天数从 11 开始编号(即第 11 天、第 22 天、第 33 天……)。若在第 dd 天吃掉第 ii 颗糖果,则会产生 (d⋅ai)(d \cdot a_i) 的糖分惩罚,因为随着时间推移,糖果会变得越来越甜。每颗糖果至多被吃一次。

总糖分惩罚等于所有被吃掉的糖果各自惩罚值之和。

假设 Yui 恰好选择 kk 颗糖果,并以任意她喜欢的顺序吃掉它们。她所能获得的最小总糖分惩罚是多少?

由于 Yui 是个优柔寡断的女孩,她希望你对每个 k=1,2,…,nk = 1, 2, \ldots, n 分别回答这个问题。

输入格式

The first line contains two integers nn and mm (1≤m≤n≤200 0001 \le m \le n \le 200\ 000).

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤200 0001 \le a_i \le 200\ 000).

第一行包含两个整数 nn 和 mm(1≤m≤n≤200 0001 \le m \le n \le 200\ 000)。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤200 0001 \le a_i \le 200\ 000)。

输出格式

You have to output nn integers x1,x2,…,xnx_1, x_2, \ldots, x_n on a single line, separed by spaces, where xkx_k is the minimum total sugar penalty Yui can get if she eats exactly kk sweets.

你需要在一行中输出 nn 个整数 x1,x2,…,xnx_1, x_2, \ldots, x_n,以空格分隔,其中 xkx_k 表示若由依恰好吃掉 kk 颗糖果时所能得到的最小总糖分惩罚值。

输入输出样例

  • 输入#1

    9 2
    6 19 3 4 4 2 6 7 8

    输出#1

    2 5 11 18 30 43 62 83 121
  • 输入#2

    1 1
    7

    输出#2

    7

说明/提示

Let's analyze the answer for k=5k = 5 in the first example. Here is one of the possible ways to eat 55 sweets that minimize total sugar penalty:

  • Day 11: sweets 11 and 44
  • Day 22: sweets 55 and 33
  • Day 33 : sweet 66

Total penalty is 1⋅a1+1⋅a4+2⋅a5+2⋅a3+3⋅a6=6+4+8+6+6=301 \cdot a_1 + 1 \cdot a_4 + 2 \cdot a_5 + 2 \cdot a_3 + 3 \cdot a_6 = 6 + 4 + 8 + 6 + 6 = 30. We can prove that it's the minimum total sugar penalty Yui can achieve if she eats 55 sweets, hence x5=30x_5 = 30.

我们来分析第一个示例中 k=5k = 5 时的答案。以下是使总糖分惩罚最小的吃掉 55 颗糖果的一种可行方案:

  • 第 11 天:糖果 11 和 44
  • 第 22 天:糖果 55 和 33
  • 第 33 天:糖果 66

总惩罚为 1⋅a1+1⋅a4+2⋅a5+2⋅a3+3⋅a6=6+4+8+6+6=301 \cdot a_1 + 1 \cdot a_4 + 2 \cdot a_5 + 2 \cdot a_3 + 3 \cdot a_6 = 6 + 4 + 8 + 6 + 6 = 30。我们可以证明,若 Yui 吃掉 55 颗糖果,则该总糖分惩罚 3030 是她所能达到的最小值,因此 x5=30x_5 = 30。

输入解题思路,AI测评打分。不知道怎么写?

首页