Greedy Florist

  • + 0 comments

    Solution in JAVA

    // Complete the getMinimumCost function below. static int getMinimumCost(int k, int[] c) {

        Arrays.sort(c);
        int res=0;
        int m=0;int counter=0;
        int i=c.length-1;
        for(;i>=0;i--)
        {
    
            if(counter%k==0 && counter>0){
                counter=0;
                m++;
            }
            System.out.println(i+" "+m+" "+counter);
            res=res+(m+1)*c[i];
            counter++;
            System.out.println(res);
        }
        return res;
    
    
    }