problem Description
Acdream Kingdom's Flower shop only one, so we want to buy flowers to decorate, the shopkeeper to prevent someone malicious hoarding flowers to raise prices (is scalpers), so set a rule: the more you buy, the next time you buy the price will be more expensive! Assuming that a person has purchased X flowers, the price of the next purchase of a flower is (x+1) *c[i], where C[i] is the basic price for a shopkeeper for each flower.
Acdream School wants to open a sports meeting, need n flowers to decorate, so you and your small partner total m individual have to find a way to spend the least amount of money to complete the task. How much do you need to spend at least wit?
Input
Multiple sets of data, each set of data is first two positive integers, n (1<=n<=100), M (1<=m<=100) and then n integers c[i], (1<=c[i]<=10^6)
Output
For each set of data, output an integer that represents the minimum price you need to spend.
Code
#include <cstdio>#include <algorithm>using namespace STD;intMain () {intN, M, a[ the]; while(scanf("%d%d", &n, &m)! = EOF) { for(inti =0; I < n; i++)scanf("%d", &a[i]); Sort (A, a + N);intAns =0, cnt =0; for(inti = n-1; I >=0; i--) {ans + = a[i] * (cnt/m +1); cnt++; }printf("%d\n", ans); }return 0;}
1714 Flower shop in Acdream Kingdom