Statistics

Problem Statement for "BasicSorting"

Problem Statement

You have a few very large files and they need to be sorted according to a total order that is defined for them. The only information you can use to sort them is the relative orders of pairs of files. Unfortunately, finding the relative order of a pair takes N*M minutes where N and M are the sizes of the two files being compared. Given the sizes of the files being sorted, your task is to find a comparison plan that guarantees you will find the correct order in the minimal amount of time. You should return that minimum.

Definition

Class:
BasicSorting
Method:
minSortTime
Parameters:
int[]
Returns:
int
Method signature:
int minSortTime(int[] sizes)
(be sure your method is public)

Notes

  • No two files are 'equal' -- one of them always belongs strictly after the other in the ordering.

Constraints

  • sizes will contain between 2 and 6 elements, inclusive.
  • Each element of sizes will be between 1 and 100, inclusive.

Examples

  1. {1,2,3}

    Returns: 11

    With 3 files, you must compare all 3 pairs of files to figure out the order. The total time is thus 1*2 + 1*3 + 2*3 = 11 minutes.

  2. {1,1,1,1}

    Returns: 5

    One way to do this is to find the order on three of the files, which takes 3 minutes. Then, compare the fourth file to the middle one of those three files. Finally, if the fourth file comes after the middle file, compare it to the last file, while if it comes before the fourth file, compare it to the first file.

  3. {15,74,61,34,21}

    Returns: 12477

  4. {1,2,3,4,5,6}

    Returns: 128

  5. {1,1,1,1,1,1}

    Returns: 10

  6. {1,2,3,4,5}

    Returns: 67

  7. {1,1}

    Returns: 1

  8. {30,40,10,45,71,78}

    Returns: 21903

  9. {30,55,31,12,62,86}

    Returns: 21425

  10. {67,93,36,45,75,3}

    Returns: 30084

  11. {15,71,15,70,2,93}

    Returns: 21878

  12. {51,85,15,8}

    Returns: 6903

  13. {57,10,69,51,96,66}

    Returns: 34515

  14. {93,76,26,3,61,64}

    Returns: 30935

  15. {44,86,75,53,96,5}

    Returns: 38263

  16. {90,78,62,92,48,81}

    Returns: 57594

  17. {82,50,27,78,70,39}

    Returns: 33919

  18. {50,49,38,53,93,65}

    Returns: 33341

  19. {23,28,84,82,44,86}

    Returns: 34090

  20. {82,90,12,2,22,74}

    Returns: 24376

  21. {9,78,16,43,18}

    Returns: 7372

  22. {84,69,42,12,94,53}

    Returns: 36539

  23. {50,19,54,42,80,24}

    Returns: 20196

  24. {57,62,16,85,96,33}

    Returns: 35167

  25. {20,61,7,80,70,12}

    Returns: 18701

  26. {42,58,61,23,56,88}

    Returns: 29498

  27. {99,75,3,12,46,37}

    Returns: 21721

  28. {88,36,80,16,39}

    Returns: 19908

  29. {24,94,35,68,77,33}

    Returns: 30271

  30. {90,79,5,66,47,97}

    Returns: 43494

  31. {75,69,54,81,32,34}

    Returns: 33728

  32. {96,33,29,66,45,39}

    Returns: 25407

  33. {59,12,10,76,37}

    Returns: 11437

  34. {87,97,97,67,46,54}

    Returns: 56790

  35. {88,90,9,26,51,21}

    Returns: 23292

  36. {58,25,95,18,65}

    Returns: 20284

  37. {43,95,66,39,74,61}

    Returns: 39667

  38. {52,19,13,49,25}

    Returns: 7480

  39. {21,22,78,7,48,17}

    Returns: 10162

  40. {85,88,73,100,61,9}

    Returns: 49900

  41. {71,33,40,34,91,65}

    Returns: 30991

  42. {30,95,5,15}

    Returns: 4950

  43. {84,4,99,86,94}

    Returns: 41764

  44. {28,72,2,14,82,43}

    Returns: 17178

  45. {31,70,18,4,44,18}

    Returns: 9692

  46. {17,11,54,89,38,38}

    Returns: 16728

  47. {57,41,70,66}

    Returns: 17415

  48. {44,54,97,20,42}

    Returns: 18818

  49. {51,31,20,39,55,75}

    Returns: 20379

  50. {47,80,8,66,50,90}

    Returns: 33474

  51. {8,28,73,96}

    Returns: 12548

  52. {80,83,47,16,74,28}

    Returns: 31020

  53. {25,45,16,73,57,36}

    Returns: 17933

  54. {30,14,86,65,77}

    Returns: 22061

  55. {65,65,53,50,72,60}

    Returns: 37246

  56. {7,33,53,9,56,6}

    Returns: 7890

  57. {17,77,7,59,59,85}

    Returns: 27697

  58. {3,95,50,36,23}

    Returns: 12017

  59. {22,27,40,71,13,94}

    Returns: 20079

  60. {3,80,96,1,33}

    Returns: 13860

  61. {25,66,89,40,55,34}

    Returns: 26345

  62. {7,85,84,41,94}

    Returns: 30242

  63. {82,45,46,89,18,47}

    Returns: 29781

  64. {78,4,35,58,54,33}

    Returns: 20021

  65. {33,79,40,2,84,69}

    Returns: 28132

  66. {84,51,25,33,37}

    Returns: 15208

  67. {32,31,39,95,77,54}

    Returns: 29346

  68. {53,64,32,53,69,24}

    Returns: 24594

  69. {68,66,88,90,60,43}

    Returns: 48424

  70. {69,2,62,36,94,58}

    Returns: 29994

  71. {71,31,97,29,22}

    Returns: 17869

  72. {93,68,17,26,35,2}

    Returns: 16899

  73. {73,80,5,55,50,23}

    Returns: 24410

  74. {36,88,28,76,3,37}

    Returns: 20836

  75. {56,75,18,30,46,21}

    Returns: 16778

  76. {71,68,82,99,27}

    Returns: 35963

  77. {37,6,46,74,19,44}

    Returns: 14680


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: