You are viewing a single comment's thread. Return to all comments →
int getMinimumCost(int k, vector c) { int minCost = 0;
if(k >= c.size()){ for(auto cost: c){ minCost += cost; } return minCost; } int prevPurchases = 0; int tempFriendsCnt = k; sort(c.begin(), c.end()); for(int i = c.size()-1; i >= 0; i--){ if(tempFriendsCnt == 0){ tempFriendsCnt = k; prevPurchases++; } minCost += (prevPurchases + 1) * c[i]; tempFriendsCnt--; } 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 →
int getMinimumCost(int k, vector c) { int minCost = 0;
}