Greedy Florist

  • + 1 comment
         Arrays.sort(c);
                            int ans=0;
                            int count=1;
                            int noOfFriendsRem=k;
                        for (int i = c.length-1; i >-1; i--) {
                                if (noOfFriendsRem==0) {
                                        noOfFriendsRem=k;
                                        count++;
                                }
                                ans+=c[i]*count;
            noOfFriendsRem--;
        }
        return ans;