Statistics

Problem Statement for "ConstructionFromMatches"

Problem Statement

There is a shop in your city, in which matches of different integer thicknesses from 1 to N, inclusive, are sold. All matches in the shop have the same length. The (i-1)-th element of cost is the cost of one match with thickness i.

You wish to buy some matches and use them to construct a 2xM rectangle. For example, if M=5, then the rectangle will look as follows (characters '|' and '-' correspond to matches):

 _ _ _ _ _
| | | | | |
 _ _ _ _ _
| | | | | |
 _ _ _ _ _

You are given two int[]s, top and bottom, each containing exactly M elements. top and bottom contain the required thicknesses of the squares in the top and bottom rows of the rectangle, respectively, from left to right. The thickness of a square is the sum of the thicknesses of its four sides. Return the minimum total cost of matches needed to construct the required rectangle, or -1 if it's not possible.

Definition

Class:
ConstructionFromMatches
Method:
minimumCost
Parameters:
int[], int[], int[]
Returns:
int
Method signature:
int minimumCost(int[] cost, int[] top, int[] bottom)
(be sure your method is public)

Constraints

  • cost will contain between 1 and 12 elements, inclusive.
  • Each element of cost will be between 1 and 100000, inclusive.
  • Elements of cost will be in strictly ascending order.
  • top will contain between 1 and 50 elements, inclusive.
  • bottom will contain the same number of elements as top.
  • Each element of top and bottom will be between 4 and 48, inclusive.

Examples

  1. {1638,3631,21834,23257,32573,33361,35554,56818,60066,60102,69211,80348}

    {8,41,30,47,15,12,37,10,34,36,29,32,42,15,8,19,32,27,8,34,22,7,24,41,32,32,36,45,4,22,9,28,16,20,24,26,25,28,30,24,15,48,22,13,30,17,7,37,29,19}

    {14,22,12,44,17,9,29,42,26,23,21,15,42,27,39,22,48,10,44,30,20,6,24,24,31,6,39,34,28,25,5,43,22,15,22,11,42,14,21,8,9,38,21,40,38,8,14,12,19,35}

    Returns: -1

  2. {10665,19996,22429,31085,43854,45183,52066,63045,65723,68213,81907,97519}

    {20,26,33,39,25,25,26,29,18,25,23,27,22,18,23,33,34,17,30,23,22,27,28,22,33,28,20,31,42,30,33,17,21,27,25,25,30,32,29,28,31,18,12,15,24,26,27,26,20,14}

    {25,29,28,29,17,39,30,27,33,30,17,27,39,27,29,27,17,16,37,32,25,22,27,21,18,21,33,23,14,21,26,18,25,37,25,21,24,27,23,35,40,19,27,17,12,30,36,19,23,20}

    Returns: 10238433

  3. {100000}

    {4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4}

    {4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4}

    Returns: 25200000

  4. {1}

    {4}

    {4}

    Returns: 7

  5. {7675,9857,12637,39508,53411,68010,69118,70753,75819,83052,85228,87250}

    {48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48}

    {48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48}

    Returns: 21987000

  6. {10198,18491,21423,24378,28105,40389,75849,76390,79224,84258,84462,95941}

    {26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26}

    {26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26}

    Returns: 9900310

  7. {1, 2}

    {7}

    {5}

    Returns: 10

    The cheapest solution contains 3 matches of thickness 2 and 4 matches of thickness 1. It may look as follows (each digit d denotes a single match of thickness d): 1 2 2 2 1 1 1

  8. {1}

    {5}

    {5}

    Returns: -1

    Obviously we can't get a square with thickness 5 using only matches of thickness 1.

  9. {1, 5, 9}

    {7, 10}

    {8, 9}

    Returns: 56

    One of the optimal solutions looks as follows (each digit d denotes a single match of thickness d): 1 3 1 3 1 2 3 1 3 1 2 2

  10. {1, 3, 4, 7, 9}

    {13, 14, 13, 11, 9, 7, 11, 8, 8, 10}

    {18, 14, 17, 10, 8, 4, 8, 13, 14, 13}

    Returns: 194

  11. {7941,14737,23818,24635,56939,64715,66473,94052,95172}

    {19,24,14,22,25,16,21,11,16,19,24,20,19,11,13,18,21,18,26,22,22,18,20,20,15,11,19,25}

    {10,19,22,25,27,9,22,23,19,17,21,24,20,20,18,7,21,15,21,25,24,21,18,17,17,21,19,18}

    Returns: 5048607

  12. {13663,18973,19514,24992,30471,36027,62979,63961,69836,70564,78700,81924}

    {24,28,29,31,31,28,20,24,21,31,28,19,19,28,27,38,23,29,23,18,16,21,27,26,27,33,35,22,25,23,26,31,30,22,27,33,26,12,21,21,43}

    {25,23,22,31,26,40,24,28,22,18,26,14,16,42,29,31,24,31,24,10,29,34,17,18,17,22,24,21,35,34,24,25,22,22,22,21,18,19,33,26,33}

    Returns: 7821010

  13. {18499,58118,81959}

    {9,7,8,6,6}

    {8,7,11,8,8}

    Returns: 1189470

  14. {15362,19707,43549,50737,68209,78002,82189,90874,97759}

    {21,12,19,19,28,21,31,22,16,20,17,17,17,18,24,20,14,18,23,13,16,19,27,22,17,17,24,21}

    {22,15,14,9,16,15,20,22,22,22,22,18,23,22,20,21,15,11,11,21,23,21,22,22,25,26,21,22}

    Returns: 6722910

  15. {16916,51229}

    {5,4,6,5}

    {7,7,8,7}

    Returns: 749595

  16. {5360,34281,66131,73523,82151,86840,89919,90228,96255,99442}

    {30,17,14,10,17,27,24,13,24,24,19,29,26,18,15,18,21,24,18,12,21,34,28,29,15,27,19,18,27,25,24,20,23,23,25,17,15,18,18,29,20,18,36,18,20,27,19,31,22}

    {27,27,22,18,26,31,21,18,22,23,17,21,22,15,9,23,21,22,22,19,9,23,30,24,15,20,28,27,28,32,23,17,20,30,22,10,13,26,16,18,21,22,26,16,21,31,27,26,24}

    Returns: 12363078

  17. {20194,44835,47283,61984,63032,80122,89443,90013,95577,99041,99377,99537}

    {26,26,30,31,29,27,29,19,36,19,18,22}

    {28,28,29,14,17,18,35,25,31,27,27,34}

    Returns: 3528990

  18. {35410,80216}

    {7,7,4,6,4,6,7,7,7,4,6,7,8,6,6,5,6,6,6,7,6,5,6,5,5,6,7,6,7,7,7,6}

    {7,7,6,8,6,6,5,6,7,6,5,5,7,5,5,4,6,6,6,7,7,6,6,7,8,7,7,7,8,6,6,6}

    Returns: 9186482

  19. {8448,17550,61886}

    {5,7,9,8,10,12,11,10,8,7,5,7,7,11,9,7,7,10,9,6,7,9,6,8,6,11,10,7,7,8,8,5,6,9,9,10,9,5,6,9,6,6,7}

    {7,8,10,6,8,8,8,10,8,5,6,11,9,8,7,6,6,10,10,6,7,8,6,7,8,7,7,7,11,8,7,6,7,6,8,9,9,10,8,9,7,7,7}

    Returns: 4838948

  20. {64919,79764}

    {7,7,7}

    {6,4,6}

    Returns: 1237228

  21. {39585}

    {4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4}

    {4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4}

    Returns: 9975420

  22. {147,5971,16919,24924,37496,50319,54675,57730,80681,90220,95579,99469}

    {17}

    {20}

    Returns: 148424

  23. {1,2,3,4,5,6,7,8,9,10,11,12}

    {48}

    {14}

    Returns: -1

  24. {1,2,3,4,5,6,7,8,9,10,11,12}

    {4}

    {37}

    Returns: 40

  25. {1,2,3,4,5,6,7,8,9,10,11,12}

    {4}

    {36}

    Returns: 39

  26. {1,2,3,4,5,6,7,8,9,10,11,12}

    {48}

    {15}

    Returns: 51

  27. {1}

    {4}

    {5}

    Returns: -1

  28. {1}

    {5}

    {4}

    Returns: -1

  29. {1}

    {48}

    {48}

    Returns: -1

  30. {4471,12539,24999,33568,39177,41918,48207,52738,54001,74676,78879,91410}

    {36,33,47,42,48,45,15,14,45,15,13,46,37,26,44,11,16,45,44,22,31,15,15,44,11,6,37,48,38,19,45,18,38,41,8,11,9,28,20,33,46,14,15,18,41,25,9,26,43,17}

    {14,45,37,9,15,12,9,33,47,14,11,37,8,4,15,12,38,37,18,38,18,4,7,35,11,29,48,46,21,4,15,4,18,45,37,44,15,9,30,13,15,27,48,47,48,47,41,16,39,44}

    Returns: 12150850

  31. {4471,12539,24999,33568,39177,41918,48207,52738,54001,74676,78879,91410}

    {37,33,47,42,48,45,15,14,45,15,13,46,37,26,44,11,16,45,44,22,31,15,15,44,11,6,37,48,38,19,45,18,38,41,8,11,9,28,20,33,46,14,15,18,41,25,9,26,43,17}

    {14,45,37,9,15,12,9,33,47,14,11,37,8,4,15,12,38,37,18,38,18,4,7,35,11,29,48,46,21,4,15,4,18,45,37,44,15,9,30,13,15,27,48,47,48,47,41,16,39,44}

    Returns: -1

  32. {4471,12539,24999,33568,39177,41918,48207,52738,54001,74676,78879,91410}

    {36,33,47,42,48,45,15,14,45,15,13,46,37,26,44,11,16,45,44,22,31,15,15,44,11,6,37,48,38,19,45,18,38,41,8,11,9,28,20,33,46,14,15,18,41,25,9,26,43,17}

    {13,45,37,9,15,12,9,33,47,14,11,37,8,4,15,12,38,37,18,38,18,4,7,35,11,29,48,46,21,4,15,4,18,45,37,44,15,9,30,13,15,27,48,47,48,47,41,16,39,44}

    Returns: -1

  33. {4471,12539,24999,33568,39177,41918,48207,52738,54001,74676,78879,91410}

    {36,33,47,42,48,45,15,14,45,15,13,46,37,26,44,11,16,45,44,22,31,15,15,44,11,6,37,48,38,19,45,18,38,41,8,11,9,28,20,33,46,14,15,18,41,25,9,26,43,16}

    {14,45,37,9,15,12,9,33,47,14,11,37,8,4,15,12,38,37,18,38,18,4,7,35,11,29,48,46,21,4,15,4,18,45,37,44,15,9,30,13,15,27,48,47,48,47,41,16,39,44}

    Returns: -1

  34. {4471,12539,24999,33568,39177,41918,48207,52738,54001,74676,78879,91410}

    {36,33,47,42,48,45,15,14,45,15,13,46,37,26,44,11,16,45,44,22,31,15,15,44,11,6,37,48,38,19,45,18,38,41,8,11,9,28,20,33,46,14,15,18,41,25,9,26,43,17}

    {14,45,37,9,15,12,9,33,47,14,11,37,8,4,15,12,38,37,18,38,18,4,7,35,11,29,48,46,21,4,15,4,18,45,37,44,15,9,30,13,15,27,48,47,48,47,41,16,39,45}

    Returns: -1

  35. {4471,12539,24999,33568,39177,41918,48207,52738,54001,74676,78879,91410}

    {36,33,47,42,48,45,15,14,45,15,13,46,37,26,44,11,16,45,44,22,31,15,15,44,10,6,37,48,38,19,45,18,38,41,8,11,9,28,20,33,46,14,15,18,41,25,9,26,43,17}

    {14,45,37,9,15,12,9,33,47,14,11,37,8,4,15,12,38,37,18,38,18,4,7,35,11,29,48,46,21,4,15,4,18,45,37,44,15,9,30,13,15,27,48,47,48,47,41,16,39,44}

    Returns: -1

  36. {4471,12539,24999,33568,39177,41918,48207,52738,54001,74676,78879,91410}

    {36,33,47,42,48,45,15,14,45,15,13,46,37,26,44,11,16,45,44,22,31,15,15,44,11,6,37,48,38,19,45,18,38,41,8,11,9,28,20,33,46,14,15,18,41,25,9,26,43,17}

    {14,45,37,9,15,12,9,33,47,14,11,37,8,4,15,12,38,37,18,38,18,4,7,35,11,30,48,46,21,4,15,4,18,45,37,44,15,9,30,13,15,27,48,47,48,47,41,16,39,44}

    Returns: -1

  37. {7232,18077,25800,34761,43098,44107,51007,51802,69686,73537,85366,96296}

    {9,9,8,10,8,6,8,8,7,8,9,7,7,7,8,7,9,8,9,6,11,9,10,9,6,6,7,10,12,9,8,8,11,7,6,8,10,6,7,9,9,9,8,8,10,10,10,11,8,8}

    {6,7,9,10,8,7,9,8,7,7,8,8,6,9,9,9,10,9,10,7,8,5,7,7,9,11,9,6,10,7,6,5,8,8,8,9,11,9,9,7,7,11,9,9,10,7,8,7,7,8}

    Returns: 3664991

  38. {6487,7519,25595,29906,32180,64102,73719,73738,76437,93723,94415,96888}

    {47,42,45,43,42,43,45,46,45,43,42,42,43,43,47,44,45,47,46,44,43,44,45,44,44,42,44,44,45,44,43,44,44,43,41,43,43,43,42,45,44,45,45,44,45,44,43,44,43,42}

    {44,41,44,44,43,46,43,43,42,42,45,46,43,42,46,46,46,43,45,45,41,42,43,44,46,41,44,43,44,43,42,45,44,44,44,42,44,42,41,44,46,45,42,42,44,45,42,43,45,43}

    Returns: 21992266

  39. {15036,16636,28671,37306,38027,38922,40416,56251,57941,59795,74701,92396}

    {22,24,30,28,28,27,25,25,30,26,26,22,29,31,31,30,28,25,25,25,27,28,27,25,21,22,24,24,29,27,24,27,25,23,21,25,31,27,26,24,21,28,27,23,25,28,21,28,24,24}

    {22,21,25,26,24,25,26,24,26,28,26,22,22,26,31,29,29,28,28,26,27,25,22,21,23,26,25,24,30,26,21,24,25,22,24,28,30,28,29,23,23,27,28,27,24,29,27,30,27,24}

    Returns: 8947943

  40. {90,652,703,1953,6539,9683,28921,33824,49086,70883,76922,92769}

    {32,37,30,32,18,18,33,29,20,36,30,24,18,20,17,19,21,27,27,31,13,27,27,25,13,15,25,21,22,26,32,27,25,29,27,26,41,38,27,44,35,24,14,24,30,27,29,22,32,26}

    {21,23,34,32,22,21,25,13,29,38,26,24,16,21,41,28,24,18,37,45,31,32,36,40,18,18,28,25,32,27,12,31,41,28,26,15,23,26,22,27,37,33,31,15,20,20,11,19,40,25}

    Returns: 5598340

  41. {146,626,945,1278,2581,6754,8761,13148,14304,32849,35850,59585}

    {11,10,7,5,8,9,12,9,8,10,6,5,8,10,8,8,6,7,6,8,6,8,8,7,7,9,7,8,8,7,7,9,12,9,9,8,6,8,6,8,6,8,6,4,8,10,10,8,9,9}

    {10,11,8,6,8,12,9,10,9,8,7,8,6,9,10,9,7,9,8,7,7,8,7,9,9,8,7,6,5,6,8,7,10,7,10,6,6,6,6,8,5,8,9,7,8,6,9,11,7,10}

    Returns: 118113

  42. {1258,13642,15476,20844,21815,29092,33807,38455,61630,65034,86430,90145}

    {43,47,47,45,45,44,44,46,44,42,43,44,46,45,41,45,45,47,47,45,43,46,43,40,42,45,45,44,45,44,40,40,42,44,45,43,43,44,45,45,45,44,46,44,45,46,47,45,44,46}

    {43,45,42,42,45,45,43,44,47,46,46,48,44,45,44,41,43,43,46,46,44,43,45,43,44,45,45,44,46,46,41,41,41,45,44,42,44,44,44,42,47,44,42,42,46,43,44,47,45,45}

    Returns: 18585276

  43. {5,842,6012,6037,8973,9503,10110,21369,27693,30289,38719,49377}

    {26,25,26,30,25,22,20,23,24,26,23,22,26,24,29,27,27,27,24,26,27,26,28,26,23,29,24,26,28,25,26,30,32,27,25,25,30,28,28,26,24,23,27,22,25,27,25,23,28,24}

    {30,26,20,24,26,25,22,29,26,25,28,27,31,27,28,26,27,25,24,25,22,28,24,26,28,29,28,28,28,25,29,29,27,22,25,25,22,23,24,24,25,25,26,26,25,26,27,23,23,22}

    Returns: 2340074

  44. {424,4498,4824,5249,12948,13504,17658,17696,36390,42435,44381,65683}

    {26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26}

    {26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26}

    Returns: 2996708

  45. {2,7,19,33,121,5838,10261,25223,49968,51517,61483,88230}

    {23,36,32,29,18,34,28,30,32,29,23,20,22,26,15,12,24,31,33,28,37,31,28,33,33,31,26,15,9,13,26,27,24,25,23,24,17,21,32,35,32,27,20,23,24,15,28,29,25,20}

    {18,31,31,30,27,29,28,20,30,28,19,31,28,19,26,25,26,31,25,7,21,25,24,25,31,15,24,29,21,26,18,19,30,20,26,31,29,32,28,31,23,24,15,16,31,24,27,37,27,21}

    Returns: 2775238

  46. {1,9,61,147,2855,3597,4012,9186,34496,46594,59842,93284}

    {7,9,9,7,7,9,8,7,8,8,11,10,8,8,6,6,9,6,6,6,5,8,8,8,10,9,11,9,10,7,7,6,12,7,9,9,7,10,7,6,6,5,7,8,6,8,6,7,6,11}

    {10,8,7,7,8,7,7,6,10,6,6,7,6,8,6,8,9,9,7,5,6,6,9,8,7,8,9,7,9,10,11,9,10,7,9,9,7,8,11,9,8,7,7,6,7,8,10,10,11,10}

    Returns: 4018

  47. {1,2,194,195,522,17262,19176,20141,21009,33740,41628,48333}

    {46,46,46,42,46,43,43,43,45,44,42,43,43,44,41,45,46,46,45,45,45,45,45,45,45,48,47,44,43,43,44,45,44,42,43,44,43,42,45,41,44,47,45,45,47,45,43,44,44,43}

    {46,47,46,42,43,42,46,46,45,43,43,44,45,43,43,43,42,45,43,44,45,44,47,44,46,46,44,44,47,43,42,47,43,43,46,45,46,42,43,41,43,47,45,43,46,43,42,46,47,46}

    Returns: 9498483

  48. {1,1471,12765,13363,16051,47837,51919,69428,72140,79413,82483,83261}

    {28,24,26,23,24,21,22,25,28,28,26,27,21,24,24,24,23,28,26,28,26,27,30,24,26,29,26,25,26,26,20,27,27,27,24,25,25,27,28,25,27,25,26,26,26,27,30,24,27,25}

    {28,25,29,26,27,24,24,24,28,27,24,25,24,26,25,27,27,23,22,28,26,23,26,28,31,30,28,23,23,25,28,31,28,27,28,30,28,27,28,22,25,27,27,25,24,26,29,25,24,28}

    Returns: 7292694

  49. {50,83,163,1662,3604,34598,54102,59614,62526,65747,67410,92836}

    {26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26}

    {26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26}

    Returns: 4098508

  50. {15255,35437,61807,63887,68598,70654,71974,78049,83112,85613,95750,95997}

    {19,32,28,26,31,26,31,32,39,30,20,24,32,19,39,31,32,41,26,29,19,26,31,30,29,33,32,29,29,18,15,29,29,36,22,21,33,40,24,21,24,32,24,27,24,39,35,22,25,21}

    {25,32,38,28,33,13,28,16,17,18,31,22,24,19,25,26,36,36,24,28,24,44,30,18,16,26,23,23,27,21,22,34,26,35,29,37,28,31,32,43,38,45,24,16,18,24,25,20,15,26}

    Returns: 13788684

  51. {22571,47694,62552,70666,71157,72604,73165,76060,87965,88848,96717,97680}

    {7,9,6,6,8,7,8,10,8,8,11,8,9,9,6,7,7,8,9,4,7,9,6,7,10,9,9,8,9,8,7,6,7,6,7,9,7,7,6,8,7,10,10,9,7,8,7,8,7,10}

    {6,10,8,8,8,8,7,7,7,6,9,9,9,8,5,7,5,8,10,8,6,7,10,9,8,8,8,7,8,7,8,6,7,6,8,6,5,8,10,10,9,10,8,8,10,9,7,9,8,10}

    Returns: 8585873

  52. {32343,52123,54482,56918,57753,60377,69696,73781,77340,81268,98408,99549}

    {41,44,41,45,47,43,45,46,44,45,42,44,47,45,48,43,46,44,44,45,41,45,46,43,43,44,44,44,45,44,42,46,44,43,44,43,43,46,45,45,41,44,46,46,44,47,45,43,44,45}

    {44,48,43,45,47,45,46,45,45,46,44,45,43,42,47,41,42,42,45,44,44,46,41,42,44,45,46,44,42,43,46,48,44,45,47,45,45,42,42,43,43,44,44,44,43,43,42,42,43,45}

    Returns: 22527920

  53. {24188,31029,51889,63616,66324,66584,66782,67719,72810,82087,86785,99202}

    {31,25,27,27,27,26,24,28,25,24,24,22,24,23,25,26,32,24,25,27,25,26,27,26,27,28,28,25,25,24,23,22,26,25,23,26,27,25,26,22,24,23,21,21,25,26,26,22,24,21}

    {24,23,29,25,26,29,25,23,26,21,26,24,26,26,23,23,26,26,24,27,24,26,27,28,25,29,24,26,24,25,26,25,26,24,20,22,26,28,27,24,25,27,24,22,24,26,26,26,25,23}

    Returns: 12888805

  54. {11352,25975,43194,71737,75398,78474,78963,90853,91499,92209,93607,99498}

    {26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26}

    {26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26}

    Returns: 11675304

  55. {37009,43834,51835,56031,67119,75175,75534,85450,88111,88487,95927,99798}

    {26,35,21,24,25,26,27,43,29,27,28,29,32,31,28,34,30,27,20,25,19,27,23,30,26,13,35,29,25,24,23,23,23,33,27,28,17,22,29,30,29,21,19,14,25,35,19,13,24,13}

    {24,42,21,19,26,35,21,29,29,29,29,20,23,38,31,21,20,22,24,25,18,20,19,22,16,15,24,19,26,22,17,30,35,25,11,17,23,34,27,24,38,30,23,18,19,28,13,23,29,13}

    Returns: 15578035

  56. {25710,49546,50715,50757,52625,53408,71900,73855,78797,86022,86702,94223}

    {9,8,8,6,6,10,8,12,8,7,9,7,6,7,7,7,8,9,6,6,7,8,8,8,10,9,9,7,10,8,6,4,6,6,6,7,6,8,6,9,9,11,8,10,10,7,8,10,8,7}

    {10,7,10,7,8,11,9,12,7,6,8,10,7,8,8,9,7,8,6,7,9,8,5,8,7,7,7,8,10,8,7,9,10,8,9,10,8,9,8,11,11,10,6,7,9,8,8,7,11,9}

    Returns: 8338568

  57. {43713,46338,47511,58502,58632,59677,60425,82454,89091,95916,97252,98272}

    {45,46,44,44,47,44,40,44,44,43,44,42,44,42,44,44,45,45,41,45,46,45,45,44,48,45,47,42,42,42,43,45,45,47,45,44,44,44,45,47,45,47,47,45,41,42,44,45,43,41}

    {43,48,44,45,47,44,42,45,44,45,44,44,46,42,43,43,47,45,42,46,47,43,44,43,45,44,46,47,45,42,42,45,44,42,40,42,44,45,44,45,44,43,45,45,43,42,42,44,42,40}

    Returns: 22859446

  58. {43069,43533,47296,57948,68077,70378,75105,79874,80207,86890,89591,94030}

    {21,20,23,25,30,28,24,26,28,29,27,23,28,23,27,27,23,27,24,26,26,25,24,23,22,25,25,27,25,28,26,23,27,26,24,28,25,24,23,22,27,25,25,24,25,26,24,25,27,30}

    {23,24,29,24,28,29,26,25,27,25,25,21,24,27,27,25,28,29,28,24,25,27,30,27,26,24,26,30,24,23,23,27,26,25,27,27,25,28,26,25,27,25,26,24,24,29,27,26,24,26}

    Returns: 15505905

  59. {35013,48515,51827,66889,72792,74136,86644,88299,91848,93329,93377,95884}

    {26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26}

    {26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26}

    Returns: 14910376

  60. {1, 3, 4, 7, 9 }

    {13, 14, 13, 11, 9, 7, 11, 8, 8, 10 }

    {18, 14, 17, 10, 8, 4, 8, 13, 14, 13 }

    Returns: 194

  61. {1, 3, 4, 7, 9 }

    {13, 14, 13, 11, 9, 7, 11, 8, 8, 10 }

    {18, 14, 17, 10, 8, 4, 8, 13, 14, 12 }

    Returns: 192

  62. {1 }

    {4 }

    {4 }

    Returns: 7

  63. {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }

    {24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24 }

    {24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24 }

    Returns: 1252

  64. {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 100000 }

    {48 }

    {4 }

    Returns: -1

  65. {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }

    {10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 }

    {10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 }

    Returns: 552

  66. {1, 3, 4, 7, 11 }

    {13, 14, 13, 11, 9, 7, 11, 8, 8, 7 }

    {18, 14, 17, 10, 8, 4, 8, 13, 14, 13 }

    Returns: 204


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: