Advertisement
Guest User

Untitled

a guest
Oct 21st, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. package olymp;
  2.  
  3. import net.egork.utils.io.InputReader;
  4. import net.egork.utils.io.OutputWriter;
  5.  
  6. public class TaskC {
  7. class Tariff {
  8. long packageSize;
  9. long timeForOneByte;
  10. long price;
  11.  
  12. public Tariff(long packageSize, long timeForOneByte, long price) {
  13. this.packageSize = packageSize;
  14. this.timeForOneByte = timeForOneByte;
  15. this.price = price;
  16. }
  17. }
  18.  
  19. public void solve(int testNumber, InputReader in, OutputWriter out) {
  20. long fileSize = in.readInt();
  21. long timeLimit = in.readInt();
  22. long time0 = in.readInt();
  23.  
  24. Tariff t1 = new Tariff(in.readInt(), in.readInt(), in.readInt());
  25. Tariff t2 = new Tariff(in.readInt(), in.readInt(), in.readInt());
  26.  
  27. long bestPrice = Long.MAX_VALUE;
  28. for (long times1 = 1; times1 <= (long)(1e7); times1++) {
  29. long bytesCanDownload1 = times1 * t1.packageSize;
  30. bytesCanDownload1 = Math.min(bytesCanDownload1, fileSize);
  31. long timeSpent1 = bytesCanDownload1 * t1.timeForOneByte;
  32. long moneySpent1 = times1 * t1.price;
  33. long timeRemaining1 = timeLimit - timeSpent1;
  34. if (timeRemaining1 < 0) {
  35. break;
  36. }
  37. long bytesRemaining1 = Math.max(0, fileSize - bytesCanDownload1);
  38.  
  39. long leftTimes2 = 0, rightTimes2 = (long)1e7, ansTimes2 = -1;
  40. while (leftTimes2 <= rightTimes2) {
  41. long times2 = (leftTimes2 + rightTimes2) / 2;
  42. long bytesCanDownload2 = times2 * t2.packageSize;
  43. bytesCanDownload2 = Math.min(bytesCanDownload2, bytesRemaining1);
  44. long timeSpent2 = bytesCanDownload2 * t2.timeForOneByte;
  45. long timeRemaining2 = timeRemaining1 - timeSpent2;
  46. if (timeRemaining2 < 0) {
  47. rightTimes2 = times2 - 1;
  48. continue;
  49. }
  50.  
  51. }
  52.  
  53. if (bytesCanDownload1 >= bytesRemaining1) {
  54. // more times1 makes no sense
  55. break;
  56. }
  57. }
  58.  
  59. if (bestPrice == Long.MAX_VALUE) {
  60. out.printLine(-1);
  61. } else {
  62. out.printLine(bestPrice);
  63. }
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement