Greedy Florist

  • + 0 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.