You are viewing a single comment's thread. Return to all comments →
c# solution:
static int getMinimumCost(int k, int[] c) { int howManyFlowers = c.Count(); Array.Sort(c); int cost = 0; int multipleCost = 1; int couterForMultipleCost = 0; if (howManyFlowers <= k) { //cost = c.Sum(); return c.Sum(); } else { do { couterForMultipleCost++; if (couterForMultipleCost > k) { couterForMultipleCost = 1; multipleCost++; } cost += multipleCost * c[howManyFlowers - 1]; howManyFlowers -= 1; } while (howManyFlowers != 0); } return cost; }
Seems like cookies are disabled on this browser, please enable them to open this website
Greedy Florist
You are viewing a single comment's thread. Return to all comments →
c# solution: