You are viewing a single comment's thread. Return to all comments →
O(n + nLogn)
int n = c.Length; int minCost = 0; int tempCount = 0; int previousPurchases = 0; Array.Sort(c); if(k >= n){ for(int i = 0; i < n; i++) minCost += c[i]; } else{ for(int i = n - 1; i >= 0; i--){ if(tempCount == k){ tempCount = 0; previousPurchases++; } minCost += (previousPurchases + 1) * c[i]; tempCount++; } } return minCost;
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# Code:
O(n + nLogn)