Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package olymp;
- import net.egork.utils.io.InputReader;
- import net.egork.utils.io.OutputWriter;
- public class TaskC {
- class Tariff {
- long packageSize;
- long timeForOneByte;
- long price;
- public Tariff(long packageSize, long timeForOneByte, long price) {
- this.packageSize = packageSize;
- this.timeForOneByte = timeForOneByte;
- this.price = price;
- }
- }
- public void solve(int testNumber, InputReader in, OutputWriter out) {
- long fileSize = in.readInt();
- long timeLimit = in.readInt();
- long time0 = in.readInt();
- Tariff t1 = new Tariff(in.readInt(), in.readInt(), in.readInt());
- Tariff t2 = new Tariff(in.readInt(), in.readInt(), in.readInt());
- long bestPrice = Long.MAX_VALUE;
- for (long times1 = 1; times1 <= (long)(1e7); times1++) {
- long bytesCanDownload1 = times1 * t1.packageSize;
- bytesCanDownload1 = Math.min(bytesCanDownload1, fileSize);
- long timeSpent1 = bytesCanDownload1 * t1.timeForOneByte;
- long moneySpent1 = times1 * t1.price;
- long timeRemaining1 = timeLimit - timeSpent1;
- if (timeRemaining1 < 0) {
- break;
- }
- long bytesRemaining1 = Math.max(0, fileSize - bytesCanDownload1);
- long leftTimes2 = 0, rightTimes2 = (long)1e7, ansTimes2 = -1;
- while (leftTimes2 <= rightTimes2) {
- long times2 = (leftTimes2 + rightTimes2) / 2;
- long bytesCanDownload2 = times2 * t2.packageSize;
- bytesCanDownload2 = Math.min(bytesCanDownload2, bytesRemaining1);
- long timeSpent2 = bytesCanDownload2 * t2.timeForOneByte;
- long timeRemaining2 = timeRemaining1 - timeSpent2;
- if (timeRemaining2 < 0) {
- rightTimes2 = times2 - 1;
- continue;
- }
- }
- if (bytesCanDownload1 >= bytesRemaining1) {
- // more times1 makes no sense
- break;
- }
- }
- if (bestPrice == Long.MAX_VALUE) {
- out.printLine(-1);
- } else {
- out.printLine(bestPrice);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement