Implement a schedule which minimizes waiting time MinimumWaitingTime.java
public static int minimumWaitingTime(List<Integer> serviceTime) {
// Sort the query time in increasing order.
Collections.sort(serviceTime);
int waiting = 0;
for (int i = 0; i < serviceTime.size(); ++i) {
waiting += serviceTime.get(i) * (serviceTime.size() - (i + 1));
}
return waiting;
}
The gasup problem GassingUp.java
int carry = 0;
Pair<Integer, Integer> min = new Pair<>(0, 0);
for (int i = 1; i < G.length; ++i) {
carry += G[i - 1] - D[i - 1];
if (carry < min.getSecond()) {
min = new Pair<>(i, carry);
}
}
return min.getFirst();
}