text: println(answer); } private static int getAnswer(Car[] cars, int[] fuels, int distance, int time) { int answer = -1; for (int left = 1, right = 1000 * 1000 * 1000; left <= right; ) { final int mid = ((left + right) >> 1); final int maxVolume = getMaxVolumeForCost(cars, mid); if (can(maxVolume, fuels, distance, time)) { answer = mid; right = mid - 1; } else { left = mid + 1; } } return answer; } private static boolean can(int volume, int[] fuels, int distance, int maxTime) { if (volume == 0) return false; int lastFuel = 0; int curTime = 0; for (int fuel : fuels) { int needDistance = fuel - lastFuel; if (needDistance > volume) { return false; } /* 2x + y = volume x + y = needDistance x = volume - needDistance */ int fastDistance = Math.min(volume - needDistance, needDistance); curTime += fastDistance + 2 * (needDistance - fastDistance); lastFuel = fuel; } return (curTime <= maxTime); } private static int getMaxVolumeForCost(Car[] cars, int cost) { int result = 0; for (Car car : cars) { if (car.cost <= cost) { result = max(result, car.volume); } } return result; } ///////////////////////////////////////////////////////////////////// private final static boolean FIRST_INPUT_STRING = false; private final static boolean MULTIPLE_TESTS = true; private final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null; private final static int MAX_STACK_SIZE = 128; private final static boolean OPTIMIZE_READ_NUMBERS = true; ///////////////////////////////////////////////////////////////////// public void run(){ try{ timeInit(); Locale.setDefault(Locale.US); init(); if (ONLINE_JUDGE) { solve(); } else { do { try { timeInit(); solve(); time(); out.println(); } catch (NumberFormatException e) { break; } catch (NullPointerException e) { if (FIRST_INPUT_STRING) break; else throw e; } } while (MULTIPLE_TESTS); } out.close(); time(); }catch (Exception e){ e.printStackTrace(System.err); System.