Codeforces Round #600 (Div. 2)C. Sweets Eating

题目链接

题意:

糖果每天最多吃m个,一共n个糖果。糖果第d天吃的花费是a[i] * d 问你吃k块糖果的最小花费是多少

思路:

具体看代码

#include <bits/stdc++.h>
using namespace std;
const int N = 1e6+10;
int n,m;
long long sum[N],a[N];
int main(){
    scanf("%d%d",&n,&m);
    for(int i = 1;i <= n;i++){
        scanf("%lld",a+i);
    }
    sort(a+1,a+1+n);
    for(int i = 1;i <= n;i++){
        if(i > m){
            sum[i] = a[i]+sum[i-m];
        }else sum[i] = a[i];
    }
    long long ans = 0;
    for(int i = 1;i <= n;i++){
        ans += sum[i];
        printf("%lld ",ans);
    }
    return 0;
}

 

posted @ 2020-11-04 22:19  Shmilky  阅读(48)  评论(0编辑  收藏  举报