You are viewing a single comment's thread. Return to all comments →
int getMinimumCost(int k, vector<int> c) { sort(c.begin(),c.end(),greater<int>()); int i=0, j=0, ans=0; while(i<c.size()) { while(k-- && i<c.size()) { ans += (j+1)*c[i]; i++; } j++; } return ans; }
Can you tell me what is wrong with my approach. 5 test cases are failing.
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 →
Can you tell me what is wrong with my approach. 5 test cases are failing.