1714 Flower shop in Acdream Kingdom

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.