Statistics

Problem Statement for "SlimeXSlimeRancher2"

Problem Statement

You are playing a game titled Slime Rancher 2. You will be training slimes in this game.

You have a slime-in-training. Associated with the slime are N attributes, numbered 0 through N-1, each represented by a positive integer. You are given int[] attributes containing N integers : the i-th integer is the initial value of the i-th attribute for the slime. After the training is complete, each of the slime's attributes will either stay the same or increase to some positive integer less than or equal to 999. None of the attributes will decrease in value. The weight of the training is defined as the sum of the differences between the final and initial values of all the attributes for the slime.

You are a master slime breeder, and you're able to obtain any possible final values for a slime's attributes. This time, you would like to create a well-balanced slime. A slime is well-balanced if all of its attributes have equal values. What is the minimum possible weight of the training?

Definition

Class:
SlimeXSlimeRancher2
Method:
train
Parameters:
int[]
Returns:
int
Method signature:
int train(int[] attributes)
(be sure your method is public)

Constraints

  • attributes will contain between 2 and 50 elements, inclusive.
  • Each element of attributes will be between 1 and 999, inclusive.

Examples

  1. {1,2,3}

    Returns: 3

    Train the slime such that all of its attributes are equal to 3. The total weight of the training is |3 - 1| + |3 - 2| + |3 - 3| = 3.

  2. {5,5}

    Returns: 0

    This slime is already well-balanced.

  3. {900,500,100}

    Returns: 1200

  4. {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,999}

    Returns: 48902

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

    Returns: 0

  6. {1,1}

    Returns: 0

  7. {999,999}

    Returns: 0

  8. {1,999}

    Returns: 998

  9. {999,1}

    Returns: 998

  10. {999,998}

    Returns: 1

  11. {1,2}

    Returns: 1

  12. {1,999}

    Returns: 998

  13. {999,1}

    Returns: 998

  14. {1,999}

    Returns: 998

  15. {999,1}

    Returns: 998

  16. {1,1,1}

    Returns: 0

  17. {999,999,999}

    Returns: 0

  18. {1,999,1}

    Returns: 1996

  19. {999,1,999}

    Returns: 998

  20. {999,998,999}

    Returns: 1

  21. {1,2,1}

    Returns: 2

  22. {1,999,1}

    Returns: 1996

  23. {1,999,999}

    Returns: 998

  24. {1,500,999}

    Returns: 1497

  25. {999,500,1}

    Returns: 1497

  26. {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}

    Returns: 0

  27. {999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999}

    Returns: 0

  28. {1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999}

    Returns: 24950

  29. {999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1}

    Returns: 24950

  30. {999,998,999,998,999,998,999,998,999,998,999,998,999,998,999,998,999,998,999,998,999,998,999,998,999,998,999,998,999,998,999,998,999,998,999,998,999,998,999,998,999,998,999,998,999,998,999,998,999,998}

    Returns: 25

  31. {1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2}

    Returns: 25

  32. {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,999,1,1,1,1,1,1,1,1}

    Returns: 48902

  33. {999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,1,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999}

    Returns: 998

  34. {1,21,41,62,82,102,123,143,163,184,204,225,245,265,286,306,326,347,367,387,408,428,449,469,489,510,530,550,571,591,612,632,652,673,693,713,734,754,774,795,815,836,856,876,897,917,937,958,978,999}

    Returns: 24974

  35. {999,978,958,937,917,897,876,856,836,815,795,774,754,734,713,693,673,652,632,612,591,571,550,530,510,489,469,449,428,408,387,367,347,326,306,286,265,245,225,204,184,163,143,123,102,82,62,41,21,1}

    Returns: 24974

  36. {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}

    Returns: 0

  37. {999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999}

    Returns: 0

  38. {1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1}

    Returns: 24950

  39. {999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999,1,999}

    Returns: 23952

  40. {999,998,999,998,999,998,999,998,999,998,999,998,999,998,999,998,999,998,999,998,999,998,999,998,999,998,999,998,999,998,999,998,999,998,999,998,999,998,999,998,999,998,999,998,999,998,999,998,999}

    Returns: 24

  41. {1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1}

    Returns: 25

  42. {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,999,1,1,1,1,1,1,1,1,1,1}

    Returns: 47904

  43. {999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,1,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999}

    Returns: 998

  44. {1,21,42,63,84,104,125,146,167,188,208,229,250,271,292,312,333,354,375,396,416,437,458,479,500,520,541,562,583,603,624,645,666,687,707,728,749,770,791,811,832,853,874,895,915,936,957,978,999}

    Returns: 24474

  45. {999,978,957,936,915,895,874,853,832,811,791,770,749,728,707,687,666,645,624,603,583,562,541,520,500,479,458,437,416,396,375,354,333,312,292,271,250,229,208,188,167,146,125,104,84,63,42,21,1}

    Returns: 24474

  46. {110,830,308,631,555,234}

    Returns: 2312

  47. {371,248,180,869,774,80,442,562,611,337}

    Returns: 4216

  48. {733,897,381,405,469,282,921,341,659,385,818,186,941,535,600,263,470,470,591,66,856,187,99,787,745,385,28,147,404,526,546,159,240,573,562,241,121,121,845,332,305,383,548,495,805,944,585,245,394}

    Returns: 23235

  49. {289,287,502,140,65,760,618,644,319,656}

    Returns: 3320

  50. {324,836,538,114,632,356,522,113,223,13,556,896,92,581,1,327,182,440,244,934,187,962,224,450,191,796,642,650,950,694,866,597,585,745,569}

    Returns: 16638

  51. {789,895,593,315,261,145,634,560,679,226,809,870,674,47,467,378,701,865,397,186}

    Returns: 7409

  52. {257,539,576,378,673,732,242,303,621,819,542,567,648,213,613,126,33,66,733,192,782,920,537,614,452,945,107,859,227}

    Returns: 13089

  53. {7,974,604,706,685,141,841,865,236,481,342,730,137,930,680,946,67,193,781,428,918,770,890,197,751,436,736,712,289,184,414,178,586,849,533,837,481,772}

    Returns: 15705

  54. {984,564,883,810,397,485,140,967,678,171,691,545,894,660,867,853,264,833,965,118,614,94,95,613,616,88,266,144,27,261,256,463,529,781,528,637,689,489,610,483}

    Returns: 18308

  55. {896,532,221,928,798,7,929,730,923,846,661,565,121,324,206,433,427,30,502,339,684,655,713,360,425,527,371,702,848,133,569,58,81,278,532,28,297,7,508,812,875,364,862}

    Returns: 18840

  56. {976,704}

    Returns: 272

  57. {831,933,11}

    Returns: 1024

  58. {388,546,7,503,930}

    Returns: 2276

  59. {935,869,11,595,162,688,671,877}

    Returns: 2672

  60. {273,78,142,910,124,295,596,455,431,609,957,62}

    Returns: 6552

  61. {290,324,36,139,751,7,126,852,961,897,891,962,417,274,763,753,696}

    Returns: 7215

  62. {570,942,479,372,558,354,337,350,320,537,438,733,974,780,585,343,208,824,242,521,435,826,163,318,327}

    Returns: 11814

  63. {55,774,608,585,873,919,643,595,981,664,470,425,769,204,401,464,186,85,479,471,131,867,569,59,882,682,464,291,382,382,2,116,318,160,526,480}

    Returns: 18354

  64. {403,369,303,818,819,700,826,394,123,948,690,789,831,484,980,734,95,70,356,780,105,353,123,693,176,790,594,574,331,533,243,892,763,247,182,80,84,613,427,588,273,418,90,475,253,703,321,843,789,171}

    Returns: 24761

  65. {2,1}

    Returns: 1

  66. {998,998}

    Returns: 0

  67. {93,43}

    Returns: 50

  68. {917,962}

    Returns: 45

  69. {935,948}

    Returns: 13

  70. {234,521}

    Returns: 287

  71. {526,874}

    Returns: 348

  72. {2,1,1,2,1,2,1,1,1,2}

    Returns: 6

  73. {999,999,998,999,998,998,998,998,998,998}

    Returns: 7

  74. {78,83,27,1,10,14,51,6,15,25}

    Returns: 520

  75. {970,905,982,949,938,934,990,993,946,949}

    Returns: 374

  76. {901,7,70,37,983,941,32,916,25,967}

    Returns: 4951

  77. {383,276,952,729,368,582,558,301,708,659}

    Returns: 4004

  78. {810,697,748,252,377,629,887,970,337,264}

    Returns: 3729

  79. {2,2,1,2,1,1,1,2,2,2,2,2,2,1,1,1,1,1,2,1,2,1,1,1,2,1,2,1,1,1,1,1,1,1,1,1,2,1,1,2,1,1,1,1,1,2,2,1,2,2}

    Returns: 31

  80. {998,999,999,998,999,998,998,999,998,999,998,999,998,999,999,998,998,998,998,998,999,998,998,998,999,998,999,999,998,998,999,998,999,998,999,998,998,999,998,998,999,998,998,998,998,999,999,999,998,998}

    Returns: 30

  81. {77,82,40,81,100,26,28,45,95,98,33,43,60,93,88,27,77,85,14,63,71,95,69,68,80,40,23,32,86,24,21,13,90,78,89,94,48,97,54,100,21,42,13,7,87,11,25,89,11,3}

    Returns: 2164

  82. {959,944,900,908,906,901,947,932,986,985,905,950,933,975,899,925,953,972,964,899,976,967,980,974,961,973,960,966,901,928,994,964,927,980,966,953,918,956,997,985,928,968,991,902,909,982,981,974,993,982}

    Returns: 2271

  83. {920,909,901,900,11,932,948,34,92,50,27,918,63,41,44,51,73,33,985,947,951,975,969,34,939,27,75,915,44,928,38,907,40,984,12,73,903,952,944,954,79,983,17,71,84,962,15,992,905,956}

    Returns: 23993

  84. {433,854,266,176,41,118,745,746,483,148,377,826,10,637,976,739,898,553,885,665,922,776,536,409,355,290,345,323,323,931,299,466,416,655,808,274,463,762,750,740,606,859,987,63,880,927,528,974,16,679}

    Returns: 21412

  85. {550,931,337,528,639,216,828,467,991,580,329,667,737,813,984,614,483,935,475,121,96,484,470,257,484,167,799,371,288,441,23,68,680,925,719,737,59,139,734,650,815,996,562,902,910,295,272,597,912,131}

    Returns: 22592

  86. {999, 998 }

    Returns: 1

  87. {299, 777, 888, 777, 555, 444, 65, 56, 6, 6, 5, 3, 23, 23, 2, 3, 3, 4, 4, 4, 4 }

    Returns: 14697

  88. {900, 100, 100, 500, 100, 50 }

    Returns: 3650

  89. {9, 6, 8, 7, 3 }

    Returns: 12

  90. {3, 1, 2 }

    Returns: 3

  91. {2, 4, 1 }

    Returns: 5

  92. {1, 3, 7 }

    Returns: 10

  93. {900, 500, 100 }

    Returns: 1200

  94. {8, 1, 1 }

    Returns: 14

  95. {1, 6, 7 }

    Returns: 7

  96. {1, 5, 5, 5, 5, 6 }

    Returns: 9

  97. {1, 1, 2, 2, 5, 7 }

    Returns: 24

  98. {10, 8, 9, 7 }

    Returns: 6

  99. {3, 2, 4 }

    Returns: 3

  100. {8, 3, 5 }

    Returns: 8

  101. {1, 3, 2 }

    Returns: 3

  102. {10, 20, 35 }

    Returns: 40

  103. {1, 5, 5 }

    Returns: 4


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: