链接:https://codeforces.com/contest/1253/problem/C

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 aiai.

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,…). Eating the sweet ii at the dd-th day will cause a sugar penalty of (d⋅ai)(d⋅ai), 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.

Input

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

The second line contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤200 0001≤ai≤200 000).

Output

You have to output nn integers x1,x2,…,xnx1,x2,…,xn on a single line, separed by spaces, where xkxk is the minimum total sugar penalty Yui can get if she eats exactly kk sweets.

Examples

input

Copy

9 2
6 19 3 4 4 2 6 7 8

output

Copy

2 5 11 18 30 43 62 83 121

input

Copy

1 1
7

output

Copy

7

Note

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⋅a1+1⋅a4+2⋅a5+2⋅a3+3⋅a6=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=30x5=30.

题解:

#include<cstdio>
#include<iostream>
#include<cstring>
#include<map>
#include<set>
#include<algorithm>
using namespace std;
long long n,m,b,x,y,t,r,k,s=0;
long long a[1000001];
long long dp[1000001];
int main()
{cin>>n>>m;for(int i=1;i<=n;i++){cin>>a[i];}sort(a+1,a+1+n);for(int i=1;i<=n;i++){if(i<m)dp[i]=a[i];elsedp[i]=a[i]+dp[i-m];}for(int i=1;i<=n;i++){s+=dp[i];cout<<s<<" ";}return 0;
}

C. Sweets Eating相关推荐

  1. 【CodeForces 1253C --- Sweets Eating】DP

    [CodeForces 1253C --- Sweets Eating]DP Description Tsumugi brought n delicious sweets to the Light M ...

  2. CodeForces 1253 C. Sweets Eating DP

    一.内容 Tsumugi brought n delicious sweets to the Light Music Club. They are numbered from 1 to n, wher ...

  3. CodeForces 1253C Sweets Eating

    一共n个糖果,每天最多吃m个.糖果第d天吃的花费是a[i] * d 问你吃k块糖果的最小花费是多少.其实应该是一个贪心的思路.让糖果从大小排序然后求个前缀和就行了. AC代码: #include &l ...

  4. C - Sweets Eating 前缀和 + 思维找规律

    传送门 思路:1.找出最优策略 2.优化代码 最主要的是如何优化代码,我们发现m是一个周期,在m周期类的元素不会受到影响,一旦到达一个周期,那么此时的数值就要整体移一位,这个可以用前缀和来实现. 设d ...

  5. Codeforces 1253/C. Sweets Eating(前缀和+找规律)

    传送门 题意:给定一个长度为n的序列,代表每个糖果的糖度,每颗糖果经过d天后糖度将变为 d*ai ;xx每天最多可以吃k课糖果,问怎么选择糖果,使得吃掉 g 颗糖果xx获得的最少糖度:例如:n=9,k ...

  6. C. Sweets Eating(cf)dp

    原题链接:Problem - 1253C - Codeforces 题目大意: 糖果每天最多吃m个,一共n个糖果.糖果第d天吃的花费是a[i] * d 问你吃k块糖果的最小花费是多少. 思路:先把每颗 ...

  7. codeforces 1500分题部分题解(1249c2 770a 1264a 1253c 114b)

    C2. Good Numbers (hard version) 注意 3x 意思是 3^x time limit per test2 seconds memory limit per test256 ...

  8. [BZOJ] 1609: [Usaco2008 Feb]Eating Together麻烦的聚餐

    1609: [Usaco2008 Feb]Eating Together麻烦的聚餐 Time Limit: 10 Sec  Memory Limit: 64 MB Submit: 1646  Solv ...

  9. 如何理解Eating这个词?云原生与微服务专场介绍

    点击上方"开源社"关注我们 | 作者:开源社 | 编辑:李明康 | 责编:袁睿斌 有一幅曾经传播很广的漫画,大意是:软件吞噬世界,开源吞噬软件.后来这个漫画又被人加了两条鱼:云计算 ...

最新文章

  1. 【数据结构学习】顺序栈 C语言
  2. Win10开始菜单中的天气不更新问题的解决方法
  3. MATLAB plot画图后横轴去除空白
  4. 基于Spring boot 2.1 使用redisson实现分布式锁
  5. 前端ui 后台管理系统 简洁_Github上前端不可不知的可视化后台管理系统(1)
  6. iOS 多参数 ...NS_REQUIRES_NIL_TERMINATION 的写法
  7. phpcms导航高亮:“首页” 高亮显示(含代码、截图、案例)
  8. 汇编学习--7.16--外中断
  9. vue封装element-ui的table组件,灵活配置表头实现表格内编辑,按钮,链接等功能。...
  10. 让Safari更好用,10款实用Safari扩展推荐
  11. 蓝牙音箱连接成功但没有声音还是电脑的声音
  12. 微信修改步数 Android,安卓微信怎么改步数
  13. Flask图片验证码注册功能
  14. 【文档生成工具Doxygen介绍】
  15. [图论]最大流问题(Maximum flow)的定义
  16. 赏金猎人:德州堕胎法案 | 经济学人早报精选20210902
  17. java审计之XXE
  18. Error creating bean with name ‘sqlSessionFactory‘ defined in class path reso
  19. 三行CSS代码搞定镜头平移(Panning Shot)动画
  20. Qt如何支持高分辨率屏幕(高分屏)

热门文章

  1. Clion使用Socket报错undefined reference to `__imp_WSAStartup‘(解决办法)
  2. 纯属巧合,解决了一个困扰许久的问题,关于网卡设置时提示“系统找不到指定文件”。
  3. 光芒四射(Shining)
  4. VR全景的应用及拍摄
  5. activiti包容网关(Inclusive Gateway)
  6. uniapp引入 uView
  7. 用上GIT你一定会爱上他
  8. practical vim2 笔记
  9. 数据分析-第一章:数据载入及初步观察
  10. java cep aactor_IT系统监控的规则引擎-CEP