* 两个数表示答案 * @param n int整型 一次运输的冰激凌数量 * @param m int整型 总冰激凌数 * @param t int整型 一次运输的时间 * @param c int整型一维数组 表示每个冰激凌制作好时间<1e4 * @return int整型一维数组 */ public int[] icecream (int n, int m, int t, int[] c) { // write code here
quickSort(c, 0, m-1);
int totalTime = t; int times = 1; int indicator = c[m-1]; int[] gap = new int[m/n+1]; int index = 0; for (int i = m-1-n; i >= 0; i-=n) { times++; int waitTime = indicator - c[i] - t*2; if (waitTime > 0) { totalTime += indicator - c[i]; gap[index++] = waitTime; } else { totalTime += t*2;
return new int[]{totalTime, times}; } public static void quickSort(int[] list, int low, int high) { if (low < high){ int middle =getMiddle(list, low, high); quickSort(list, low, middle - 1); quickSort(list,middle + 1, high); } }
public static void swap(int[] param, int left, int right) { int temp = param[left]; param[left] = param[right]; param[right] = temp; }
private static int getMiddle(int[] list, int low, int high) { int tmp =list[low]; while (low < high){ while (low < high && list[high] >= tmp) { high--; } list[low] =list[high];