Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static int minimumTotalCost(int[] departures, int[] returns, int minGap) {
- int res = Integer.MAX_VALUE;
- int minDeparture = Integer.MAX_VALUE; // Tracks minimum departure in valid window
- for (int R = 0; R < departures.length; R++) {
- // Only update minDeparture when we reach a valid window
- if (R >= minGap) {
- minDeparture = Math.min(minDeparture, departures[R - minGap]);
- res = Math.min(res, returns[R] + minDeparture);
- }
- }
- return res == Integer.MAX_VALUE ? -1 : res;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement