We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int k = in.nextInt();
int[] A = new int[n];
for (int i = 0; i < n; i++) {
A[i] = in.nextInt();
}
Arrays.sort(A);
int sum = 0;
for (int i = n - 1; i >= 0; i--) {
sum += A[i] * ((n - i - 1) / k + 1);
}
System.out.println(sum);
}
Greedy Florist
You are viewing a single comment's thread. Return to all comments →