You are viewing a single comment's thread. Return to all comments →
Java solution. The problem should be under easy section(I may be wrong).
static int getMinimumCost(int k, int[] c) { int cost = 0; Arrays.sort(c); int multiplier = 0; int count = k; for (int i = c.length - 1; i >= 0; i--) { cost += (multiplier + 1) * c[i]; count--; if (0 == count) { multiplier++; count = k; } } return cost; }
Greedy Florist
You are viewing a single comment's thread. Return to all comments →
Java solution. The problem should be under easy section(I may be wrong).