【CodeForces 1253C --- Sweets Eating】DP

Description

Tsumugi brought n delicious sweets to the Light Music Club. They are numbered from 1 to n, where the i-th sweet has a sugar concentration described by an integer ai.

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

Days are 1-indexed (numbered 1,2,3,…). Eating the sweet i at the d-th day will cause a sugar penalty of (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 k 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 k between 1 and n.

Input

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

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

Output

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

Sample Input

9 2
6 19 3 4 4 2 6 7 8

Sample Output

2 5 11 18 30 43 62 83 121

AC代码:

#include <bits/stdc++.h>
using namespace std;
#define SIS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define endl '\n'
using ll = long long;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int MAXN = 2e5+5;
ll arr[MAXN],dp[MAXN];int main()
{SIS;ll n,m,sum=0;cin >> n >> m;for(int i=1;i<=n;i++) cin >> arr[i];sort(arr+1,arr+n+1);for(int i=1;i<=n;i++){sum+=arr[i];if(i<m) dp[i]=sum;else dp[i]=dp[i-m]+sum;cout << dp[i] << " ";}return 0;
}

【CodeForces 1253C --- Sweets Eating】DP相关推荐

  1. CodeForces 1253C Sweets Eating

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

  2. 【CodeForces 332B --- Maximum Absurdity】递推

    [CodeForces 332B --- Maximum Absurdity]递推 题目来源:点击进入[CodeForces 332B - Maximum Absurdity] Description ...

  3. 【CodeForces 1255D --- Feeding Chicken】

    [CodeForces 1255D --- Feeding Chicken] Description Long is a huge fan of CFC (Codeforces Fried Chick ...

  4. 【CodeForces 1255B --- Fridge Lockers】

    [CodeForces 1255B --- Fridge Lockers] Description Hanh lives in a shared apartment. There are n peop ...

  5. 【CodeForces 1257C --- Dominated Subarray】

    [CodeForces 1257C --- Dominated Subarray] Description Let's call an array t dominated by value v in ...

  6. 【Codeforces #167 Div1 Div2】Solutions

    [A. Dima and Friends] http://www.codeforces.com/contest/272/problem/A 题目大意:n+1个人出手指头,加起来再做类似约瑟夫的出圈,问 ...

  7. 【Codeforces 321E / BZOJ 5311】【DP凸优化】【单调队列】贞鱼

    目录 题意: 输入格式 输出格式 思路: DP凸优化的部分 单调队列转移的部分 坑点 代码 题意: 有n条超级大佬贞鱼站成一行,现在你需要使用恰好k辆车把它们全都运走.要求每辆车上的贞鱼在序列中都是连 ...

  8. 【Codeforces Gym - 101635C Macarons 】【矩阵快速幂+状压】【dfs时间换空间】

    [链接] http://codeforces.com/gym/101635/attachments [题意] 求用1*1,1*2的方格填n*m的矩阵的方法数 [知识点] 状压dfs+矩阵快速幂 [分析 ...

  9. 【Codeforces Round #438 C】 Qualification Rounds

    [链接]h在这里写链接 [题意] 给你n个问题,每个人都知道一些问题. 然后让你选择一些问题,使得每个人知道的问题的数量,不超过这些问题的数量的一半. [题解] 想法题. 只要有两个问题. 这两个问题 ...

最新文章

  1. CheckM——国家微生物科学数据中心云工具
  2. ART基因序列生成器,究竟是做什么的?
  3. LeetCode每日一题 844. 比较含退格的字符串
  4. 后端技术:命名不规范,lombok泪两行!
  5. 误删path怎么办(已重启)
  6. bash: pcre-config: 未找到命令..._Docker 常用操作命令
  7. 【IDEA】Error:java: Compilation failed: internal java compiler error
  8. 问题解决 Visual Studio 2015 无法复制文件“D:\swapfile.sys”
  9. 用AUTOCAD建模的篮球
  10. java520.1314表白_520最新表白公式,拿去不谢!
  11. linux之VMware安装Centos7
  12. 菜刀之中国蚁剑-安装使用及下载地址
  13. 使用dom4j把XML文件解析成JavaBean
  14. 2019年win10最精简版本——win10企业2019长期服务版本下载和激活密钥
  15. 沟通CTBS立白集团远程接入成功案例
  16. 利用python的pyqt5和vtk库实现对gcode模型的全彩预览
  17. 天翼网关刷linux,天翼网关3.0-中兴F650光猫最新固件 开Telnet教程
  18. windows powershell 将U盘启动盘还原回普通U盘
  19. oracle11g broker,张欣橙Oracle11g配置DGbroker
  20. 5G 38.300 Rel15 中文版

热门文章

  1. 【教程】腾讯云智服客服系统快速上手指南
  2. @Component
  3. BP神经网络算法基本原理,bp神经网络算法公式
  4. 鱼骨图解释为什么我喜欢狗
  5. 盗链是什么?如何防止盗链?
  6. 破解excel密码保护
  7. 穷人瞧不起的暴利赚钱项目, 富人却在偷偷地发着横财!
  8. python中response对象的方法_Response对象的常用属性
  9. Nginx通过max_fails和fail_timeout在进行HTTP运行状况检查
  10. cefsharp 最新稳定版104.4.240 (chromium-104.0.5112.102)