Statistics

Problem Statement for "MonthlyPayment"

Problem Statement

Byterland Mobile, a mobile phone service provider, normally charges 10 cents per SMS (text message). In addition, it also offers monthly packs, which let you purchase a certain number of SMSs each month at a special price. You may purchase any number of these packs. If you exceed the number of SMSs covered by your monthly packs, the excess messages are charged at the normal rate.

You expect to send totalSMS SMSs each month, and you would like to minimize your monthly payment. There are two monthly packs available. The first pack costs pay1 cents and includes pack1 messages, and the second pack costs pay2 cents and includes pack2 messages. You may purchase any combination of these packs. Remember that it is sometimes cheaper to buy more SMSs than you actually need (see example #2). Return the minimal monthly payment in cents.

Definition

Class:
MonthlyPayment
Method:
minimalPayment
Parameters:
String, String, String, String, String
Returns:
long
Method signature:
long minimalPayment(String totalSMS, String pack1, String pay1, String pack2, String pay2)
(be sure your method is public)

Notes

  • For technical reasons, we cannot use long parameters, so we are using Strings instead.

Constraints

  • totalSMS will be an integer between 0 and 1012, inclusive, with no extra leading zeroes.
  • pack1, and pack2 will each be an integer between 1 and 1012, inclusive, with no extra leading zeroes.
  • pay1 and pay2 will each be an integer between 1 and 1013, inclusive, with no extra leading zeroes.
  • pay1 will be less than or equal to 20 * pack1.
  • pay2 will be less than or equal to 20 * pack2.

Examples

  1. "92"

    "10"

    "90"

    "20"

    "170"

    Returns: 790

    The first pack offers 10 messages for 90 cents, and the second pack offers 20 messages for 170 cents. You want to buy 92 messages, so you choose one of the first pack and four of the second pack. You will pay for the remaining 2 messages at the normal rate of 10 cents each. The total price is 90 + 170*4 + 10*2 = 790 cents.

  2. "90"

    "10"

    "90"

    "20"

    "170"

    Returns: 770

  3. "99"

    "10"

    "90"

    "20"

    "170"

    Returns: 850

    We can buy five of the second pack. The total number of SMSs covered by the purchased packs exceeds 99, but this is the cheapest way.

  4. "10"

    "1"

    "11"

    "20"

    "300"

    Returns: 100

    Packs do not lead to a cheaper way in this case.

  5. "0"

    "10"

    "80"

    "50"

    "400"

    Returns: 0

  6. "28"

    "1"

    "10"

    "1"

    "8"

    Returns: 224

  7. "152"

    "7"

    "61"

    "9"

    "53"

    Returns: 901

  8. "226"

    "5"

    "58"

    "1"

    "11"

    Returns: 2260

  9. "384"

    "1"

    "7"

    "1"

    "6"

    Returns: 2304

  10. "447"

    "1"

    "11"

    "5"

    "45"

    Returns: 4025

  11. "580"

    "5"

    "33"

    "5"

    "25"

    Returns: 2900

  12. "614"

    "3"

    "21"

    "1"

    "9"

    Returns: 4302

  13. "780"

    "1"

    "9"

    "9"

    "60"

    Returns: 5214

  14. "824"

    "3"

    "16"

    "7"

    "66"

    Returns: 4400

  15. "920"

    "9"

    "83"

    "5"

    "26"

    Returns: 4784

  16. "1028"

    "4"

    "20"

    "3"

    "32"

    Returns: 5140

  17. "1188"

    "9"

    "62"

    "1"

    "6"

    Returns: 7128

  18. "1280"

    "5"

    "40"

    "5"

    "56"

    Returns: 10240

  19. "1332"

    "5"

    "56"

    "1"

    "11"

    Returns: 13320

  20. "1480"

    "5"

    "59"

    "7"

    "78"

    Returns: 14800

  21. "1550"

    "3"

    "31"

    "7"

    "57"

    Returns: 12627

  22. "1688"

    "1"

    "5"

    "1"

    "11"

    Returns: 8440

  23. "1728"

    "7"

    "64"

    "3"

    "29"

    Returns: 15802

  24. "1800"

    "1"

    "10"

    "3"

    "24"

    Returns: 14400

  25. "1996"

    "1"

    "9"

    "5"

    "28"

    Returns: 11181

  26. "9185162344"

    "221"

    "2247"

    "977"

    "6364"

    Returns: 59830475476

  27. "93596042432"

    "343"

    "3479"

    "111"

    "1053"

    Returns: 887897591747

  28. "118506995368"

    "339"

    "1988"

    "409"

    "2602"

    Returns: 694961377394

  29. "196035318013"

    "593"

    "6892"

    "71"

    "650"

    Returns: 1794689531110

  30. "228364637727"

    "66"

    "545"

    "33"

    "239"

    Returns: 1653913588403

  31. "285265176848"

    "369"

    "4305"

    "255"

    "2223"

    Returns: 2486841129944

  32. "300356326080"

    "113"

    "1256"

    "633"

    "4486"

    Returns: 2128591594940

  33. "382959486836"

    "904"

    "6536"

    "659"

    "4247"

    Returns: 2468025707345

  34. "421160949792"

    "929"

    "7706"

    "853"

    "7811"

    Returns: 3493505144448

  35. "461577615324"

    "257"

    "1404"

    "284"

    "2612"

    Returns: 2521614677306

  36. "544501885528"

    "345"

    "3573"

    "345"

    "2556"

    Returns: 4034048752260

  37. "574746364312"

    "349"

    "4120"

    "937"

    "11049"

    Returns: 5747463643120

  38. "631987707652"

    "89"

    "799"

    "879"

    "10211"

    Returns: 5673687397931

  39. "683292664232"

    "657"

    "4844"

    "977"

    "7516"

    Returns: 5037853372944

  40. "749802968960"

    "401"

    "4184"

    "649"

    "7692"

    Returns: 7498029689600

  41. "775569470184"

    "88"

    "812"

    "481"

    "4542"

    Returns: 7156391020396

  42. "813982138895"

    "977"

    "9821"

    "133"

    "1198"

    Returns: 7331959416626

  43. "897047618224"

    "501"

    "3236"

    "871"

    "9565"

    Returns: 5794103977248

  44. "913182183940"

    "633"

    "5047"

    "281"

    "2471"

    Returns: 7280932831511

  45. "998349763552"

    "937"

    "5541"

    "849"

    "6645"

    Returns: 5903795135388

  46. "46546956728"

    "3143"

    "35290"

    "264129"

    "1572081"

    Returns: 277045003628

  47. "158913370480"

    "102945"

    "1212396"

    "107649"

    "547923"

    Returns: 808853795214

  48. "276449422336"

    "210649"

    "2099791"

    "159809"

    "850830"

    Returns: 1471828695420

  49. "365059511406"

    "260993"

    "2191288"

    "279825"

    "1539026"

    Returns: 2007812742884

  50. "450702146848"

    "63791"

    "433956"

    "115281"

    "666125"

    Returns: 2604279739220

  51. "537322901112"

    "360339"

    "3303613"

    "76039"

    "596384"

    Returns: 4214295054208

  52. "653504390400"

    "204653"

    "1990562"

    "57333"

    "636964"

    Returns: 6356325151392

  53. "777909874788"

    "341441"

    "3907700"

    "20761"

    "167820"

    Returns: 6288176639370

  54. "828393439984"

    "323937"

    "2350514"

    "130177"

    "1251711"

    Returns: 6010892283288

  55. "966707152106"

    "18695"

    "204468"

    "329809"

    "2845099"

    Returns: 8339304165068

  56. "43253205504"

    "26145712030"

    "131147554904"

    "29748828881"

    "241386341620"

    Returns: 262295109808

  57. "97242106488"

    "24463754853"

    "175311782079"

    "36220474081"

    "253196659158"

    Returns: 685079135125

  58. "141988023104"

    "20141951085"

    "196811411823"

    "23766366945"

    "161506837394"

    Returns: 969041024364

  59. "157698297856"

    "9737824788"

    "58811087081"

    "48708311529"

    "353699793104"

    Returns: 959908405776

  60. "238435501056"

    "5030352657"

    "41912362228"

    "22565993481"

    "113321757325"

    Returns: 1244190907026

  61. "281155055868"

    "19931849665"

    "163424762733"

    "17969132287"

    "128955350533"

    Returns: 2050510973625

  62. "338609577788"

    "5249306697"

    "27697117595"

    "17385285678"

    "162183408728"

    Returns: 1799155017880

  63. "362532107432"

    "46482659201"

    "393000856788"

    "12356975288"

    "65297680848"

    Returns: 1935430985392

  64. "410965965568"

    "35880653505"

    "260465631090"

    "31337668277"

    "190388383892"

    Returns: 2510811770266

  65. "470139736796"

    "47333626817"

    "258675320509"

    "26426838523"

    "223196077818"

    Returns: 2586753205090

  66. "516562711176"

    "12997447911"

    "126472051156"

    "44220762113"

    "287597219993"

    Returns: 3451166639916

  67. "557274110224"

    "10972841525"

    "95237195001"

    "40337767861"

    "238605427749"

    Returns: 3340475988486

  68. "601481373408"

    "9246197811"

    "53204540849"

    "6275686089"

    "51515535430"

    Returns: 3463080312115

  69. "673450493665"

    "10773001937"

    "100558386396"

    "10704043917"

    "105409866206"

    Returns: 6289863692262

  70. "749590646339"

    "43410108853"

    "237050310820"

    "28302190865"

    "195469786312"

    Returns: 4146043242320

  71. "766781549588"

    "25723275777"

    "145299513509"

    "33458863265"

    "298197581126"

    Returns: 4358985405270

  72. "801654279150"

    "23349100017"

    "130263352526"

    "20389402770"

    "190052124090"

    Returns: 4506802771604

  73. "882985080064"

    "17728923824"

    "107893919972"

    "49176099946"

    "402579369500"

    Returns: 5394695998600

  74. "949571669292"

    "28879179183"

    "267415078555"

    "12575549057"

    "90925828983"

    Returns: 6883492073895

  75. "980165417728"

    "25315083237"

    "127066092917"

    "35013024433"

    "265005476039"

    Returns: 4955577623763

  76. "42"

    "10"

    "20"

    "3"

    "6"

    Returns: 84

  77. "45"

    "6"

    "12"

    "7"

    "14"

    Returns: 90

  78. "54"

    "15"

    "10"

    "12"

    "8"

    Returns: 36

  79. "54"

    "12"

    "8"

    "15"

    "10"

    Returns: 36

  80. "54"

    "12"

    "16"

    "15"

    "20"

    Returns: 72

  81. "63"

    "10"

    "10"

    "8"

    "9"

    Returns: 67

  82. "19"

    "1"

    "11"

    "18"

    "65"

    Returns: 75

  83. "99"

    "46"

    "183"

    "27"

    "101"

    Returns: 385

  84. "62"

    "48"

    "199"

    "35"

    "160"

    Returns: 320

  85. "70"

    "923"

    "2239"

    "16"

    "140"

    Returns: 620

  86. "0"

    "25315083237"

    "127066092917"

    "35013024433"

    "265005476039"

    Returns: 0

  87. "1000000000000"

    "3"

    "6"

    "1"

    "3"

    Returns: 2000000000001

  88. "1000000000000"

    "3"

    "6"

    "1"

    "4"

    Returns: 2000000000002

  89. "999999999999"

    "10"

    "60"

    "99999999999"

    "599999999995"

    Returns: 5999999999995

  90. "10000000000"

    "10"

    "50"

    "1"

    "10"

    Returns: 50000000000

  91. "900400000100"

    "1001000"

    "9010000"

    "1000000"

    "9001000"

    Returns: 8104499502000

  92. "999888777677"

    "45007"

    "405063"

    "62129"

    "559161"

    Returns: 8998998999093

  93. "999999999971"

    "100"

    "100"

    "110"

    "111"

    Returns: 999999999987

  94. "100000000050"

    "100000000000"

    "100000000001"

    "100000000001"

    "100000000005"

    Returns: 100000000495

  95. "1000000000000"

    "999"

    "999"

    "1000000000000"

    "1000000000000"

    Returns: 1000000000000

  96. "75"

    "11"

    "11"

    "10"

    "10"

    Returns: 75

  97. "98765432199"

    "16"

    "144"

    "18"

    "162"

    Returns: 888888889792

  98. "450342146848"

    "6379123"

    "4339561"

    "1152481"

    "6636125"

    Returns: 306359987917

  99. "111"

    "6"

    "2"

    "9"

    "3"

    Returns: 37

  100. "190000034"

    "17"

    "17"

    "190000000"

    "190000000"

    Returns: 190000034

  101. "1000000000000"

    "321332423443"

    "654456575657"

    "213123122111"

    "443223122121"

    Returns: 2195359395556

  102. "1000000000000"

    "1"

    "20"

    "999999999999"

    "1000000000000"

    Returns: 1000000000010

  103. "117"

    "16"

    "56"

    "18"

    "65"

    Returns: 419


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: