3.26~Flowers

转载注明出处:http://www.cnblogs.com/ligun123/archive/2013/03/26/2982472.html

题目来源:https://www.hackerrank.com/challenges/flowers

You and your K-1 friends want to buy N flowers. Flower number i has cost ci. Unfortunately the seller does not like a customer to buy a lot of flowers, so he tries to change the price of flowers for customer who had bought flowers before. More precisely if a customer has already bought x flowers, he should pay (x+1)*ci dollars to buy flower number i.
You and your K-1 firends want to buy all N flowers in such a way that you spend as less money as possible.

Input:

The first line of input contains two integers N and K (K <= N) next line contains N positive integers c1,c2,…,cN respectively.

Output:

Print the minimum amount of money you (and your friends) have to pay in order to buy all N flowers.

Sample input :

3 3
2 5 6

Sample output :

13

Explanation :
In the example each of you and your friends should buy one flower. in this case you have to pay 13 dollars.

Constraint :

1 <= N, K  <= 100
Each ci is not more than 1000,000

不贴代码,说说思路,很简单,先买最贵的,再买最便宜的~

转载于:https://www.cnblogs.com/ligun123/archive/2013/03/26/2982472.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值