Statistics

Problem Statement for "TicketPrinters"

Problem Statement

After 2 years of hard work, it is finally time to unveil the ultimate plan to win the lottery. This plan involves mostly cartomancy, falsification and programming. The tarot specialist has already predicted the N numbers of the required lottery tickets, and they are given as a int[] wantedValues. The falsification specialist has prepared a set of N ticket printers and he has taken a number of security measures to make it very hard to discover the scheme:

  • The printers are in separate locations. For convenience, they are all hidden inside houses that are all on a single street. The distances between each consecutive pair of printers are given by int[] printerDistance, which contains (n-1) elements. For each i, the time required to travel between printer i and printer i+1 is printerDistance[i] seconds.
  • The way a printer functions is by keeping a hidden integer number in its memory. For security, increasing or decreasing the number by one requires 1 second. At any time, it is possible to order the printer to print the number it has in memory. This procedure also takes 1 second. The starting number for printer i is startingValues[i]
  • Each printer can print at most one ticket.
Your role as the programmer is to go to each printer and print the required lottery tickets given by wantedValues. You are currently in the same location as printer number currentPrinter. Since you do not understand why they even hired a programmer for the scheme, you have decided to use programs to save time in this process. The first program you have developed can, given a wanted number, modify the one in the printer by automatically increasing or decreasing it and finally print the wanted number automatically (increasing/decreasing the numbers and printing them still requires one second). You can install this program to each printer once you are its location. The installation doesn't take any time. Once the program is installed, it can work without any administration from your side, so you can immediately proceed to the next printer.

Now your task is to develop the second program that should determine in which order to visit printers and which printer to use for printing of each of the tickets. Return the outcome of the second program, i.e., the minimum time that is necessary to finish printing all the required numbers.

Definition

Class:
TicketPrinters
Method:
minTime
Parameters:
int, int[], int[], int[]
Returns:
int
Method signature:
int minTime(int currentPrinter, int[] printerDistance, int[] startingValues, int[] wantedValues)
(be sure your method is public)

Constraints

  • wantedValues will contain between 1 and 16 elements, inclusive.
  • startingValues will contain n elements, where n is the number of elements in wantedValues.
  • printerDistance will contain exactly n-1 elements.
  • currentPrinter will be between 0 and n-1, inclusive.
  • Each element of startingValues, printerDistance and wantedValues will be between 1 and 1000000, inclusive.
  • Each element of wantedValues will be unique.

Examples

  1. 0

    {100, 20, 50}

    {66, 78, 99, 5}

    {99, 5, 78, 66}

    Returns: 171

  2. 1

    {50, 50}

    {100, 200, 300}

    {101, 201, 302}

    Returns: 152

    A possible way to print the tickets is: 0 seconds: Start printing program up at printer 1 to print ticket #201. Begin moving to printer 2's position. 1 second: Printer 1 reaches number 201 in memory. 2 seconds: Printer 1 finishes printing its assigned ticket. 50 seconds: Arrive at printer 2's location. Order it to print ticket #302. Begin moving to printer 0's position. 52 seconds: Printer 2 reaches number 302 in memory. 53 seconds: Printer 2 finishes printing its assigned ticket. 150 seconds: Arrive at printer 0's location. Order it to print ticket #101. 151 seconds: Printer #0 reaches number #101 in memory. 152 seconds: Printer #0 finishes printing ticket #101.

  3. 2

    {13, 26, 39, 13}

    {123, 12, 32, 67, 1015}

    {1, 2, 3, 4, 5}

    Returns: 1063

  4. 8

    {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}

    {449787,614796,54968,786527, 9485, 580565, 863481, 75981, 376144, 655003, 614014, 539809, 530316, 933720, 331977, 852299}

    {148911, 505520, 471407, 703590, 782713, 363320, 731199, 777341, 60611, 774001, 184862, 12720, 874230, 522316, 477209, 433213}

    Returns: 147122

  5. 8

    {50786, 9196, 512090, 32939, 100741, 474428, 989373, 365848, 206504, 208140, 267419, 131983, 895520, 480880, 967392}

    {80756, 615730, 38519, 835172, 587564, 969197, 369071, 339844, 550224, 8133, 295471, 373624, 842247, 329170, 929143, 856805}

    {691887, 84678, 281133, 247894, 325949, 391053, 27407, 278613, 882012, 35383, 88651, 735921, 53944, 854962, 552751, 640832}

    Returns: 8230484

  6. 8

    {1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000}

    {825015, 365678, 782634, 669323, 73089, 402264, 340636, 560740, 923439, 937302, 202493, 169405, 314695, 417505, 816568, 202512}

    {564314, 773352, 351322, 429090, 36700, 681711, 549163, 27962, 124314, 959102, 388989, 917978, 49109, 318801, 979671, 394050}

    Returns: 22051664

  7. 8

    {1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000}

    {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}

    {999981,999903,999938,999956,999995,999985,999922,999974,999950,999911,999924,999972,999996,999957,999988,999992}

    Returns: 22999903

  8. 2

    {12398,16350,41097}

    {373859,152054,223916,395003}

    {635542,497593,500631,497941}

    Returns: 361890

  9. 2

    {848091,272744,37065,438282}

    {826358,36950,198537,767967,435356}

    {184405,282255,92828,600999,826697}

    Returns: 2071869

  10. 7

    {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}

    {1, 10000, 20000, 30000, 40000, 50000, 60000, 70000, 80000, 90000, 100000, 110000, 120000, 130000, 140000, 150000}

    {70120, 80119, 120075, 90114, 10042, 20065, 100105, 30084, 140029, 15, 130054, 110092, 50110, 150000, 60117, 40099}

    Returns: 121

    Longest printer path.

  11. 7

    {833,833,833,833,833,833,833,833,833,833,833,833,833,833,833}

    {1, 6250, 12500, 18750, 25000, 31250, 37500, 43750, 50000, 56250, 62500, 68750, 75000, 81250, 87500, 93750}

    {149127, 88722, 93750, 111657, 149965, 126232, 122880, 12496, 137475, 134961, 41236, 66645, 107467, 143710, 145386, 151212}

    Returns: 84548

  12. 11

    {815957,959658,801536,304948,938192,334144,839946,518049,618209,629917,803656,319834,5427,348356}

    {707053,310305,611893,355078,15681,567445,577542,509126,940313,789138,273893,104316,876398,804027,361141}

    {317574,32666,344354,514018,714658,294010,503061,962020,191525,455023,942506,876702,111734,165558,949336}

    Returns: 8919052

  13. 1

    {866458,728380,635891,990078,187196,709492,150641,148798,699244,782087,702540,532925,830954,803228,800035}

    {281537,161017,893925,39010,711378,219769,930952,583407,268015,901345,183897,575256,908311,739613,380464,767911}

    {893837,717808,174832,923668,834152,212598,230544,644466,898077,334188,132613,828070,342150,985389,242079,988658}

    Returns: 10484509

  14. 5

    {428894,844249,243529,240280,833469,806014,194162,169375,157095,3712,127171,725772,380077,596851}

    {184789,370080,930141,769107,937129,363798,468012,155058,900975,747015,877693,297172,375536,991320,423076}

    {347159,430134,131938,937457,441212,235461,609388,566134,876155,453967,322447,834867,720850,51231,62893}

    Returns: 8348130

  15. 3

    {363774,593089,214284,129720,869054,643295,816990,786900,158516,502550,628279,728184,908980}

    {350241,407845,242096,309915,936769,979717,640096,9450,504893,501881,672417,199231,789715,894609}

    {668358,173002,29298,190042,851399,805138,521410,481802,95430,4198,117064,22295,917993,200288}

    Returns: 8538147

  16. 14

    {768431,767543,445771,452071,618058,805757,131017,453370,294776,333281,696672,922405,237991,603187}

    {274934,73907,81255,300990,952125,693464,883932,610120,89292,948021,789599,84180,901886,844685,990438}

    {559019,305566,351751,438703,585364,675764,867813,437882,980147,514875,999615,955229,972726,29106,723227}

    Returns: 7560963

  17. 0

    {851225,629932,193144,395060,75370,749098,159313,673616,586646,153568,495022,279116,899591,734646,587157}

    {283373,305651,162774,850954,627964,494793,595841,386664,883734,460062,447811,637987,628622,260559,980019,226273}

    {780911,957634,866639,567511,928070,94303,42794,312249,49545,532165,501539,774903,787307,869676,154728,460386}

    Returns: 7534050

  18. 1

    {722268,14821,212472,248390,489687,269438,295336,727257,792877,751207,777732,284405,65808,893722,118394}

    {235219,131798,13948,615113,291367,456947,680554,628955,118032,763653,441160,921048,385679,366144,923153,858505}

    {955229,340300,577331,842889,672764,451049,196426,333396,820352,256511,705858,796180,905641,672126,989834,941685}

    Returns: 7401699

  19. 14

    {86930,227926,735175,497231,391264,892498,194403,925518,243951,916448,49201,220501,999539,54222}

    {167481,880584,346140,817142,687759,688586,835491,444700,534176,459239,759318,628620,559655,546465,937965}

    {175397,280224,411913,402428,986616,735355,688487,121764,836348,811827,651912,953033,607626,448410,949338}

    Returns: 6442724

  20. 2

    {603598,77643,866684,919921,940607,733840,523180,806657,936828,576625,144622,852176,287357,120340,169144}

    {997731,231848,732389,37561,152769,52914,361758,383698,779642,306263,74984,599478,914486,55073,658555,190803}

    {426521,887307,927091,384021,818575,853103,27408,717674,578175,333901,656102,556715,210403,252274,509721,441031}

    Returns: 9260064

  21. 0

    {273941,144043,1656,456034,706651,437759,520165,523399,341093,843481,591714,562805,181266,826868,373223}

    {215534,386733,886071,773356,918360,702755,560141,200537,181856,498247,280171,918537,361181,692949,525231,595164}

    {465630,996111,649865,211295,161869,615173,826440,787810,261468,166309,206368,674560,228324,198403,2944,319313}

    Returns: 6804108

  22. 2

    {789855,592816}

    {503419,132339,995992}

    {631023,747292,127381}

    Returns: 1510276

  23. 1

    {949632,519969}

    {955787,686312,318377}

    {274855,619735,589257}

    Returns: 2325623

  24. 1

    {689150}

    {24836,717002}

    {829549,66005}

    Returns: 730320

  25. 0

    {487843}

    {492302,39247}

    {727027,782028}

    Returns: 1175624

  26. 0

    {}

    {547422}

    {882777}

    Returns: 335356

  27. 0

    {557318}

    {1353,473688}

    {863969,510152}

    Returns: 862617

  28. 0

    {}

    {218280}

    {327290}

    Returns: 109011

  29. 1

    {170486,179715}

    {505307,153376,249652}

    {82739,522510,284708}

    Returns: 547120

  30. 2

    {796094,231488}

    {19190,137746,399170}

    {998901,873618,192601}

    Returns: 1200994

  31. 1

    {178607,152632}

    {398509,897591,874871}

    {706625,313189,932691}

    Returns: 567667

  32. 1

    {3}

    {6,7}

    {3,2}

    Returns: 7

  33. 0

    {2}

    {5,9}

    {8,7}

    Returns: 4

  34. 1

    {10,2}

    {3,6,4}

    {3,6,8}

    Returns: 15

  35. 0

    {}

    {5}

    {2}

    Returns: 4

  36. 2

    {6,7}

    {3,6,7}

    {4,10,3}

    Returns: 14

  37. 9

    {33109,293899,790252,110632,605485,650155,927961,994995,419997,370625,706686,875372,883487,426975,857276}

    {747884,81336,634176,552605,84631,827356,957315,879395,438404,370352,780882,924502,55335,452624,303715,639372}

    {713426,881226,499008,12482,488585,862798,420259,102360,358250,182431,351263,599744,758027,608138,372275,605788}

    Returns: 13077471

  38. 14

    {385853,32642,881350,846022,133461,907453,482652,823377,675316,502551,896387,86220,297835,51488,169620}

    {508705,229935,136673,52957,543267,219,974747,499161,195057,320958,441081,18742,904746,646352,196661,380879}

    {131925,696829,23679,757941,280120,368655,837058,52814,135575,29401,49386,473192,632150,152189,396989,847195}

    Returns: 7377361

  39. 1

    {929013,990827,804363,95964,443642,331128,244820,330385,90670,117645,688243,428778,145748,625541,422103}

    {29990,904473,353717,622747,541661,871757,524670,428718,359005,237363,201235,388455,589090,989440,574906,157292}

    {775184,103410,775280,275520,593312,422970,894530,24345,30027,951903,667157,877540,376076,520189,184104,989661}

    Returns: 7644696

  40. 7

    {192680,656550,173328,26599,715624,656960,390853,230728,96395,874325,739917,774507,644501,835967,297159}

    {22331,786894,678995,144424,946594,784478,671138,866207,78791,771412,92265,474519,757619,158116,235744,518399}

    {977044,399292,979163,119919,987732,698199,451646,861470,272119,434323,292238,90789,40555,379220,613241,322620}

    Returns: 10185441

  41. 0

    {144038,194069,318557,106729,146330,23678,272596,375451,616554,352846,724137,916250,67429,172458,669453}

    {489344,839115,823340,646296,933784,373619,560685,77326,472917,951590,698786,724215,793376,993666,34367,857392}

    {823257,432123,288628,209125,552194,789308,789009,827576,913967,796533,384015,340842,199298,609551,777941,149058}

    Returns: 5130392

  42. 14

    {757622,546410,870550,441852,807111,929693,801057,995497,675546,897051,568697,832535,357911,390258,586338}

    {940702,881779,836935,85723,648128,52324,712036,275536,895193,847888,550415,214035,857265,93518,692753,377549}

    {360021,291512,262048,856213,184004,502891,34804,362915,589564,32454,5659,834728,493884,64590,896492,197014}

    Returns: 11088677

  43. 5

    {624175,418501,103123,92490,239394,564636,662636,75202,388112,938811,29957,509369,289896,321066,541418}

    {165783,320936,17225,742053,196249,447384,241023,161221,488418,524417,43034,946492,831804,620838,711987,316649}

    {714893,892053,402720,214779,213259,917938,201943,472895,691619,807456,840534,731845,784486,974101,901986,682501}

    Returns: 7362541

  44. 6

    {429255,892982,883244,834786,268585,306056,242126,353747,343907,824019,152276,69494,779790,542123,843553}

    {831241,929326,712012,629154,785517,312044,568827,139980,821011,466755,183616,837579,540502,188515,600424,272022}

    {722229,134286,729047,80001,338015,406113,828993,182810,53479,223542,163528,700887,272362,645034,593054,127633}

    Returns: 11381192

  45. 13

    {866506,408928,510410,653732,987182,346341,21568,211920,930520,661652,848336,732183,993009,147898,441956}

    {19860,352931,409069,581532,990838,525683,534378,97929,775287,149608,158152,237067,283133,785001,398887,524372}

    {236044,2407,265364,365788,527135,417098,989245,403751,956040,946495,561095,911375,973071,654334,230479,221707}

    Returns: 9369449

  46. 11

    {477685,956563,808025,404379,21885,212508,873574,238043,733451,894452,76383,660057,314861,322982,727551}

    {263977,27031,637829,441062,325922,983373,526279,510167,440009,786553,669924,41993,954426,858476,350168,512987}

    {141627,741280,725868,55630,175814,831203,318671,946064,201852,18340,90898,858913,452713,296001,276825,305747}

    Returns: 9760699

  47. 9

    {777024,28950,19093,649205,21983,63696,154284,230705,218903,195783,642732,98499,249369,504250,660288}

    {944457,983169,923052,926080,933558,932488,945191,970097,929281,998688,945654,951323,991565,961439,987271,948845}

    {987957,970824,907621,940557,984709,954251,913734,914949,904783,923249,960271,901520,948311,992750,940331,963213}

    Returns: 6679142

  48. 0

    {618158,25574,871586,603665,827323,23166,659125,545293,118226,220398,83382,227662,300924,32005,54547}

    {993221,976855,910110,921793,924755,928631,913732,944220,902473,908404,998310,947990,975791,978489,996134,924423}

    {988362,914422,916231,944529,922199,996729,916949,972970,924891,992466,986569,958058,915874,926392,959777,932296}

    Returns: 5211503

  49. 15

    {643269,774113,78869,440071,736105,449362,175281,999770,658751,422645,541353,85927,281483,747414,854525}

    {988952,948533,994310,940351,909588,948392,920848,931715,939097,935182,907037,947149,951821,900593,902869,924196}

    {976499,902124,971700,995603,931548,962169,913024,956946,906676,955993,913311,950753,911568,984560,925347,971698}

    Returns: 7893331

  50. 10

    {444290,88357,108191,733284,621473,55358,503890,16453,645646,454661,453345,92329,511964,575019,812356}

    {974964,916745,970400,906950,962339,969499,985840,971102,910510,964634,958869,957117,996351,901573,983634,977489}

    {959235,994821,960275,929419,926980,993569,994410,929390,908887,989722,927865,920924,952701,932256,949142,947944}

    Returns: 8576319

  51. 1

    {2749,172526,68757,908954,108303,818644,82370,738426,978168,843105,923407,655842,692366,294776,327331}

    {954142,959312,994667,916291,952878,902609,944112,996189,938809,999944,977886,906927,916473,970015,944873,926045}

    {989469,945383,911487,984942,905847,968166,981549,903988,906699,985159,969019,915898,992094,950530,935022,943615}

    Returns: 7627451

  52. 6

    {49255,781031,689945,541916,465203,10119,210696,834268,638863,797965,417605,139006,972751,570734,131238}

    {917186,919839,956721,956231,928464,982472,924812,943135,919165,987888,996868,950750,917489,972447,995924,903157}

    {913545,936974,939048,976298,979454,913346,984088,980183,912543,994767,918975,908406,914119,907290,997859,960966}

    Returns: 9792198

  53. 6

    {425085,280031,533225,139527,731018,860077,770284,905644,616397,192412,71940,388508,3626,810521,303431}

    {991645,966785,961945,948731,925292,970187,932323,976237,944317,985331,948129,974455,999956,973048,959228,959046}

    {971724,978864,921855,920267,976899,988982,926900,992153,966965,948920,952824,997998,990069,972632,954564,919040}

    Returns: 10005172

  54. 10

    {810580,573058,194682,736645,535487,203678,652261,976996,90946,754269,271643,248790,327307,771514,984632}

    {938864,906426,975073,905549,990951,912693,967993,949356,996326,966131,988875,953756,983431,904267,976494,992652}

    {960840,975704,909883,939676,930363,965640,956561,907364,911751,991428,963165,959137,950562,929047,914912,927320}

    Returns: 10737187

  55. 12

    {145112,849905,527352,823049,93973,459298,883213,217494,411345,439200,297848,560477,937132,531981,463296}

    {997856,924083,942420,900293,917393,908290,934992,903616,935763,932751,918529,997309,957825,968808,918161,982935}

    {927361,967840,970491,944609,986731,916056,927032,978503,936446,965740,915759,970667,910460,974066,963326,981904}

    Returns: 9584210

  56. 3

    {577294,891471,226962,80666,968974,625166,525464,450175,427507,765850,377526,878574,456394,757301,571676}

    {978932,942907,992672,963507,904871,901751,917831,947706,962134,919821,978763,955989,906863,917774,933586,976957}

    {969477,987935,938531,958176,975480,925992,941142,944739,904715,988677,999560,944295,937034,914723,990456,953181}

    Returns: 10278205

  57. 6

    {26921,908849,598610,653620,242717,506587,134505,773013,203341,684591,644428,513085,802336,845456,686777}

    {961778,968840,937993,996275,916344,914984,991020,991652,913643,947245,948039,922852,978483,942378,956789,975727}

    {33471,6259,52002,56467,17491,2237,11291,87302,85977,96799,21747,64686,48928,75005,83202,68805}

    Returns: 12041069

  58. 3

    {768501,700716,212821,226699,999882,168437,817283,569297,409929,101117,616878,409338,402487,993213,815412}

    {999203,945326,935817,953573,913416,943321,991989,987238,934543,979935,991176,929196,997764,942217,954908,929317}

    {79061,84422,82661,67658,46080,32984,71410,90664,36475,1232,84141,19282,14426,65798,57255,10757}

    Returns: 10732702

  59. 15

    {970271,280581,874385,483748,653112,756985,346978,68796,973616,31955,20006,524053,498547,310888,120812}

    {923981,967405,989622,942180,932939,981054,946181,972547,919519,973704,917481,919121,981193,909792,954803,974423}

    {83006,46983,57967,66565,20228,97667,58039,61697,95974,74693,55411,86161,41924,90477,24187,19035}

    Returns: 7741048

  60. 9

    {189188,479616,573098,818015,477911,567296,795324,143759,512538,555423,3668,200221,617363,322203,823574}

    {996617,995302,944300,983962,939544,923642,914774,985394,977042,959301,960798,985829,909904,903144,985181,912682}

    {42507,56068,14025,41908,48151,70278,36297,63649,22608,71539,57080,16055,67652,5929,79892,67798}

    Returns: 10518375

  61. 11

    {410575,545203,504449,714050,774933,391968,664457,471904,680880,633408,986786,745187,969265,955555,73004}

    {936968,945193,940186,963914,946541,959089,931306,913177,920843,921272,975277,988564,932418,970878,970739,918509}

    {96981,80473,66036,95107,29708,66219,79416,99956,36496,3280,92006,26578,47111,25959,91538,34865}

    Returns: 13101648

  62. 15

    {930959,332638,324671,78643,100101,775917,664065,812443,518659,126427,465049,799064,236527,254847,843700}

    {987793,905194,988986,908169,962460,954323,987882,925005,991533,967771,909001,927757,958813,946548,945657,934117}

    {25020,39718,1496,43449,22243,33743,6040,83560,43203,38133,68982,21907,80954,23153,29160,15132}

    Returns: 8167944

  63. 0

    {857883,512041,449291,77611,879542,339158,250897,639668,125643,178310,999159,638506,451337,850053,65404}

    {909048,936578,940959,965765,923996,955361,920432,925329,919600,974953,954896,995596,940957,913521,910557,989751}

    {98871,88828,93305,71797,49149,75765,70404,25660,16091,26668,38368,53867,57774,33184,87209,31861}

    Returns: 8205384

  64. 3

    {782381,545297,874718,49347,337409,326856,596471,52466,345538,352080,704067,868391,87216,840205,18953}

    {997856,967271,916834,989246,917089,982294,958720,994568,949449,951942,979453,978067,995486,901521,967456,909015}

    {2988,93376,7171,55006,7605,45171,38736,61005,59713,20778,46368,21546,40080,29092,20953,43027}

    Returns: 9838919

  65. 14

    {148471,982019,947305,677332,824793,995800,744231,963834,621813,718733,914538,786408,176051,652881,770530}

    {925326,940791,998647,994761,943851,988310,941647,951281,965627,987692,945224,998805,937125,933983,987046,995220}

    {85508,49757,53869,11671,38173,22728,29275,86976,9382,97621,34719,81650,65581,76707,56641,88771}

    Returns: 12522975

  66. 9

    {539069,758873,728396,182278,575925,774901,896191,519331,305327,755482,155524,803850,534300,85569,837655}

    {907641,956590,981490,953297,968716,999985,922494,998472,933210,973401,951419,917503,942164,923065,928201,997224}

    {29938,90122,43751,61213,8257,31014,2398,29062,52531,28026,14935,19539,24501,68123,28393,20244}

    Returns: 12442571

  67. 8

    {598254,33267,998835,755985,52944,15808,350680,380672,685349}

    {4513,68075,12074,86200,56208,78,73107,90964,73269,65682}

    {968600,973670,998868,993439,934594,918854,958110,920339,948399,902676}

    Returns: 5455307

  68. 4

    {4127,848288,858681,828876,368850,532711,531760,539681,86035}

    {43808,30816,9658,61659,38136,86592,79563,13088,2574,56360}

    {931286,900824,954331,957368,918382,972763,991548,952217,970906,902302}

    Returns: 7523928

  69. 7

    {879677,580652,162984,411889,674381,474528,535176,963391,303655,920587,580719}

    {3899,64989,4422,19217,26139,69755,91191,61323,26867,99517,14333,12925}

    {920430,968428,939431,925308,948494,930961,910604,971628,944921,992897,983388,911098}

    Returns: 10162697

  70. 7

    {513214,901585,930119,273341,124884,9133,176335,399507,913325,403287,917721,867338,234349}

    {32698,68092,18357,80839,98962,10370,98361,25776,73359,31097,93533,58396,42968,57754}

    {913871,972396,944049,967120,952745,908301,988146,965429,997523,922226,999751,932872,950585,908656}

    Returns: 10443297

  71. 12

    {775050,233442,139746,386718,390234,751413,135685,399369,393856,118814,132163,955332,866812}

    {22415,95065,87577,45064,99633,27722,3186,1547,69541,26432,24509,10062,56777,65301}

    {940676,922955,938069,913787,927319,946749,916244,935051,922820,957553,974668,955819,982947,985223}

    Returns: 7436819

  72. 2

    {352840,330539,41322,101367,444162,601004,842845,677232,887934,385652}

    {80783,2946,86462,21882,96755,11678,27161,46225,95487,44499,33834}

    {934630,992125,985924,940749,976742,973313,943602,903716,969274,972063,902958}

    Returns: 6217401

  73. 3

    {527739,631336,277047,217305,768887,786563,328845,369384,253446,670955,804716,717186}

    {84858,15003,62901,14873,90587,13246,65771,21848,60759,24334,8378,28161,89562}

    {976711,932819,998891,914667,930150,984127,904641,998534,975910,901049,903404,926126,923873}

    Returns: 8601019

  74. 7

    {230670,180353,32119,981857,535733,464127,289814,895479,354821,409707,79726,549785,706216}

    {54440,52703,29054,6352,47029,71998,15373,88821,79337,94169,63025,31822,85080,25857}

    {995531,984191,965873,918775,924073,941642,935496,927149,980249,935203,995051,968002,955530,966322}

    Returns: 9317999

  75. 3

    {388104,749352,148702,999433,455927,446763,696623,921090,857838,918105}

    {89259,17318,21110,19314,72387,85456,11899,80680,6739,44546,9801}

    {901841,934298,943043,913507,977038,933036,948443,920522,962956,961481,962342}

    Returns: 8760136

  76. 3

    {630700,83713,215878,493740,786306,440736,995947,907020,277593,913775,785510,163702,589377,691085,477708}

    {74315,34619,31398,88168,4158,73868,23537,47229,82660,14381,82628,99342,61573,88559,95961,56494}

    {993770,929180,959926,991440,939652,946002,974864,991848,984320,954440,982034,959422,984199,903125,943151,906048}

    Returns: 10229713

  77. 4

    {999979,999917,999999,999914,999900,999995,999916,999942,999986}

    {31204,66123,97384,576,77929,35911,11641,70166,65909,92838}

    {941854,973203,978474,937127,949213,907588,963788,975076,922076,999253}

    Returns: 13814108

  78. 3

    {999980,999968,999976,999933,999992,999994,999951,999980,999914,999949,999920,999955,999983}

    {50772,339,30729,44128,57747,31269,14462,4169,50717,54675,67779,19595,85897,30474}

    {992540,951935,960083,967017,934579,989298,937967,907602,947204,980933,906789,973215,997013,935703}

    Returns: 16875735

  79. 10

    {999925,999923,999923,999900,999955,999904,999921,999933,999940,999912}

    {98022,25253,90832,75710,94164,38566,80696,33353,64771,90663,84373}

    {901319,979655,960795,985023,979194,972138,937445,906980,988756,965746,907537}

    Returns: 10802534

  80. 1

    {999984,999985,999990,999951,999972,999978,999901,999992,999947,999959,999964,999919,999995,999967}

    {66528,25529,38848,54049,75476,52441,44910,88506,99946,29445,31342,34992,7761,95254,25711}

    {998773,920734,907150,965274,984346,961593,983841,951858,994940,924387,972122,916519,989280,989893,948655}

    Returns: 15880928

  81. 8

    {999924,999920,999965,999995,999938,999900,999996,999998,999987}

    {75600,1071,64578,77986,55142,21216,1858,97959,38684,86697}

    {968850,985167,956418,968755,967766,952772,968385,973631,934378,904178}

    Returns: 10828189

  82. 2

    {999928,999918,999978,999929,999967,999998,999980,999931,999919,999960,999915,999919,999931,999969,999981}

    {42167,66871,89141,14463,57799,80485,27856,76828,91934,32358,18075,24832,36745,25330,54323,28041}

    {905982,930910,916335,967535,952394,960676,930137,992242,906202,929530,930375,947930,983536,907167,978943,962506}

    Returns: 17877011

  83. 1

    {999913,999969,999944,999998,999965,999970,999954,999930,999973}

    {32097,61508,59350,48329,66903,30018,67846,93044,63378,69794}

    {907380,916081,964978,943144,918375,916116,958241,918391,949096,986134}

    Returns: 10837116

  84. 13

    {999973,999998,999906,999928,999939,999937,999923,999935,999984,999909,999919,999973,999952,999984,999958}

    {41924,77228,58652,15209,92687,95762,18700,42963,69507,15860,45767,3328,30653,45738,39870,92165}

    {957178,910221,992150,953631,996600,908004,957693,974719,941999,944106,903933,977229,991731,941550,996572,961048}

    Returns: 17861170

  85. 9

    {999929,999991,999937,999930,999955,999942,999984,999953,999987,999947}

    {6744,14575,80623,85524,96640,86515,61485,73440,78695,974,71177}

    {965162,963444,910580,985230,912473,933977,947991,970004,942502,945815,968742}

    Returns: 11903339

  86. 8

    {999938,999983,999902,999992,999918,999969,999979,999946,999912,999924,999964,999941,999961}

    {436,73143,15152,21175,62114,19430,46931,2459,49913,70332,57120,84471,75689,56472}

    {987687,931825,936498,908580,995377,923308,979106,991058,921588,943876,933521,988371,939901,949789}

    Returns: 18907176

  87. 9

    {999975,999965,999982,999918,999983,999914,999985,999975,999949,999941,999915,999995,1000000,999964}

    {2910,403152,843461,244864,54963,523901,265030,160979,30727,988625,190832,901421,687404,206945,611257}

    {458879,339903,492719,763193,497551,862161,105441,735192,613118,138819,406272,503000,812905,326468,270088}

    Returns: 19101808

  88. 4

    {999934,999906,999917,999956,999999,999974,999913,999968,999943,999982,999905,999950}

    {633528,517278,462359,376018,694390,716354,540814,677383,126727,115487,428756,675492,495752}

    {457459,355966,727893,59029,695648,850661,647790,133925,807949,101810,95371,661337,546634}

    Returns: 16037354

  89. 6

    {999987,999917,999982,999989,999955,999985,999968,999975,999907}

    {765534,578886,989364,576912,855988,914724,97772,384932,40221,60626}

    {793695,908772,806826,844336,908044,696502,155935,977220,728929,460129}

    Returns: 12027677

  90. 9

    {999946,999991,999929,999967,999923,999961,999953,999942,999904,999931,999913}

    {578049,715164,514318,254995,25501,130625,699510,636224,357448,375429,426826,441430}

    {629885,120561,993012,120766,83002,666547,127822,266666,571111,194503,63647,734978}

    Returns: 13006143

  91. 9

    {999986,999946,999904,999943,999908,999990,999949,999953,999962,999917,999954}

    {655461,51869,992360,522430,158097,897614,644651,630646,297678,542179,678609,793646}

    {197402,688351,390907,135543,635931,214726,829493,288805,685021,611569,420121,496888}

    Returns: 13018814

  92. 1

    {999919,999951,999911,999920,999913,999923,999950,999928,999940,999996}

    {233038,330436,43825,967829,180936,930260,175370,990531,775077,606597,450303}

    {234217,526230,264826,255097,918046,258084,712468,461910,248567,545749,603871}

    Returns: 11010878

  93. 4

    {999971,999938,999905,999954,999984,999993,999946,999960,999993,999932,999997}

    {842105,242232,288088,278783,198079,978982,495064,312164,137264,709475,741624,756263}

    {603087,714914,921388,676656,114343,188692,239679,614099,729919,914077,96210,306034}

    Returns: 15025686

  94. 10

    {999913,999918,999928,999972,999907,999924,999927,999953,999999,999990,999942,999983,999910}

    {795232,778878,798748,313078,805335,373638,497976,869107,490737,397012,660070,754116,106807,968918}

    {677329,791328,678804,624957,586376,982938,113578,282722,808029,397694,968812,26760,104182,956397}

    Returns: 16003006

  95. 5

    {999971,999910,999989,999907,999949,999998,999943,999915,999909}

    {964799,318519,177259,628281,692213,355013,905466,511899,131651,498604}

    {802753,545708,123646,871469,84651,323547,70186,147191,857189,811441}

    Returns: 13092587

  96. 9

    {999924,999936,1000000,999971,999996,999981,999901,999999,999916,999921,999968,999938,999912}

    {553603,312,576058,309770,311763,205144,64872,406664,443916,759047,597503,979478,542490,696451}

    {507503,966801,273909,116332,642140,571234,624,368734,93870,71135,526566,846842,944441,910412}

    Returns: 17016734

  97. 2

    {1, 1, 1, 1 }

    {1, 1000000, 2, 1000000, 3 }

    {1, 2, 3, 4, 5 }

    Returns: 999999

  98. 2

    {13, 26, 39, 13 }

    {123, 12, 32, 67, 1015 }

    {1, 2, 3, 4, 5 }

    Returns: 1063

  99. 9

    {1000000, 1000000, 999999, 888888, 1000000, 1000000, 999999, 888888, 1000000, 1000000, 999999, 888888, 1000000, 1000000, 999999 }

    {1990, 654, 5498, 657498, 2126, 696999, 888888, 8, 9, 10, 2222, 13, 14, 1555, 7777, 4525 }

    {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16, 15, 14 }

    Returns: 20557521

  100. 0

    {1000 }

    {100, 151 }

    {200, 150 }

    Returns: 1002


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: