Skip to content

Latest commit

 

History

History
18 lines (15 loc) · 406 Bytes

greedy-florist.MD

File metadata and controls

18 lines (15 loc) · 406 Bytes

Greedy Florist (HackerRank)

https://www.hackerrank.com/challenges/greedy-florist


// Complete the getMinimumCost function below.
int getMinimumCost(int k, vector<int> c) {
    std::sort(c.begin(), c.end());
    std::reverse(c.begin(), c.end());
    
    int price_sum = 0;
    for (int i = 0; i < c.size(); ++i) {
        price_sum += c[i] * (i / k + 1);
    }
    return price_sum;
}