All submissions for this problem are available.###Problem description. A group of friends want to buy a box of electrical items. The shopkeeper wants to maximize his number of new customers and the money he makes. To do this, he decides he'll multiply the price of each item by the number of that customer's previously purchased items plus 1 . The first item will be original price (0+1) * original price , the next will be (1+1) * original price and so on. Given the size of the group of friends, the number of items they want to purchase and the original prices of the items, determine the minimum cost to purchase all of the items. For example, if there are 3 friends that want to buy items that cost c=[1,2,3,4] each will buy one of the items priced [2,3,4] at the original price. Having each purchased 1 item, the first item in the list, c will now cost (current purchase +previous purchase) * c = (1+1) * 1 =2 . The total cost will be 2 + 3 + 4 + 2 =11 ###Input The first line contains two space-separated integers n and k ,the number of items and the number of friends. The second line contains n space-separated positive integers ,c[i] the original price of each item ###Output Print the minimum cost to buy all n items. ###Constraints $1\leq n,k \leq 1000$ $0 \leq i \leq n$ ###Sample Input1: 3 3 2 5 6 ###Sample Output1: 13 ###Sample Input2: 3 2 2 5 6 ###Sample Output2: 15 ###Sample Input3: 5 3 1 3 5 7 9 ###Sample Output3: 29 ###Explanation $Example case 1.$ There are n=3 items with costs c=[2,5,6] and k=3 people in the group. If each person buys one item, the total cost of prices paid is 2+5+6 =13 dollars. Thus, we print 13 as our answer. $Example case 2.$ There are n=3 items with costs c=[2,5,6] and k=2 people in the group. We can minimize the total purchase cost like so: The first person purchases 2 items in order of decreasing price; this means they buy the more expensive item c1=5 first at price p1= (0+1) * 5 = 5 dollars and the less expensive item c0=2 second at price p0=(1+1) * 2=4 dollars. The second person buys the most expensive item at price p2=(0+1) * 6 = 6 dollars. We then print the sum of these purchases, which is , 5 + 4 + 6 =15 ,as our answer. $Example case 3.$ The friends buy items for 9,7 and 3,5 and 1 for a cost of .9+7+3 * (1+1) +5 +1 * (1+1)=29
|Time Limit:||0.1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, kotlin, PERL6, TEXT, SCM chicken, PYP3, CLOJ, COB, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.