package algorithms.greedyflorist;

import java.util.Arrays;
import java.util.Scanner;

public class Solution {

  private static final Scanner scanner = new Scanner(System.in);

  public static void main(String[] args) {
    String[] nk = scanner.nextLine().split(" ");

    int n = Integer.parseInt(nk[0]);

    int k = Integer.parseInt(nk[1]);

    int[] c = new int[n];

    String[] cItems = scanner.nextLine().split(" ");
    scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");

    for (int i = 0; i < n; i++) {
      int cItem = Integer.parseInt(cItems[i]);
      c[i] = cItem;
    }

    System.out.println(getMinimumCost(k, c));

    scanner.close();
  }

  static int getMinimumCost(int friendsCount, int[] flowersPrice) {
    Arrays.sort(flowersPrice);

    final int flowersCount = flowersPrice.length;
    final int flowerPrices = Arrays.stream(flowersPrice).sum();
    final int flowersExtra = flowersCount % friendsCount;
    final int extraPrice = Arrays.stream(flowersPrice).limit(flowersExtra).sum();

    return flowerPrices + extraPrice;
  }
}

@@ -53,16 +53,45 @@
 Arrays;%0A
+import java.util.Comparator;%0A
 import j
@@ -756,16 +756,31 @@
 e) %7B%0A   
+ flowersPrice =
  Arrays.
@@ -780,19 +780,21 @@
 Arrays.s
-ort
+tream
 (flowers
@@ -803,302 +803,266 @@
 ice)
-;%0A
 %0A    
-final int flowersCount = flowersPrice.length;%0A    final int flowerPrices = Arrays.stream(flowersPrice).sum();%0A    final int flowersExtra = flowersCount %25 friendsCount;%0A    final int extraPrice = Arrays.stream(flowersPrice).limit(flowersExtra).sum();%0A%0A    return flowerPrices + extraPrice
+  .boxed()%0A      .sorted(Comparator.reverseOrder())%0A      .mapToInt(Integer::valueOf)%0A      .toArray();%0A%0A    int sum = 0;%0A%0A    for (int i = 0; i %3C flowersPrice.length; i++) %7B%0A      sum += flowersPrice%5Bi%5D * ((i / friendsCount) + 1);%0A    %7D%0A%0A    return sum
 ;%0A  

fix the greedy florist implementation