Statistics

Problem Statement for "SkiResortsEasy"

Problem Statement

Fox Ciel is the owner of a ski resort. The ski resort has N places numbered 0 through N-1. You are given a int[] altitude. For each i, the i-th element of altitude is the altitude of the place i.

The skiers would like to follow the path (place 0) -> (place 1) -> ... -> (place N-1). The trip will only be possible if the altitudes of the places are non-increasing. In order to make the trip possible, Ciel now needs to decrease the altitudes of some places. In other words, Ciel wants to decrease some of the altitudes so that altitude[0] >= altitude[1] >= ... >= altitude[N-1] holds. It costs 1 unit of money to decrease the altitude of one place by 1 unit of height.

Return the minimal cost required for the change.

Definition

Class:
SkiResortsEasy
Method:
minCost
Parameters:
int[]
Returns:
int
Method signature:
int minCost(int[] altitude)
(be sure your method is public)

Constraints

  • altitude will contain between 2 and 50 elements, inclusive.
  • Each element of altitude will be between 0 and 1,000, inclusive.

Examples

  1. {30, 20, 20, 10}

    Returns: 0

    The altitudes are already non-increasing, so Ciel doesn't need to change anything.

  2. {5, 7, 3}

    Returns: 2

    Ciel should change the altitude of place 1 (0-based index) from 7 to 5. This changes the sequence of altitudes to {5, 5, 3}. The cost of the change is 7 - 5 = 2 units of money.

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

    Returns: 6

    Ciel should change the altitudes to {6, 6, 5, 4, 4, 4, 2, 2, 1}.

  4. {23, 507}

    Returns: 484

  5. {249, 739, 471}

    Returns: 712

  6. {836, 515, 256, 985}

    Returns: 729

  7. {893, 564, 67, 59, 902}

    Returns: 843

  8. {539, 162, 187, 745, 413, 621}

    Returns: 1318

  9. {781, 478, 793, 32, 6, 212, 130}

    Returns: 645

  10. {870, 78, 227, 622, 930, 554, 578, 597}

    Returns: 3040

  11. {533, 901, 375, 989, 799, 37, 120, 842, 548}

    Returns: 2805

  12. {749, 560, 921, 166, 757, 818, 228, 584, 366, 88}

    Returns: 2284

  13. {733, 985, 965, 457, 553, 172, 880, 763, 421, 30, 327, 233}

    Returns: 2628

  14. {386, 932, 176, 785, 56, 705, 223, 336, 835, 770, 498, 674, 677, 848}

    Returns: 6217

  15. {112, 574, 224, 410, 3, 860, 502, 37, 123, 748, 392, 714, 319, 374, 747, 646}

    Returns: 6301

  16. {371, 272, 95, 980, 335, 830, 669, 491, 949, 465, 529, 220, 878, 888, 117, 57, 66, 747}

    Returns: 6910

  17. {712, 745, 230, 200, 648, 440, 115, 913, 627, 621, 186, 222, 741, 954, 581, 193, 266, 320, 798, 745}

    Returns: 6393

  18. {290, 943, 836, 208, 421, 991, 972, 684, 448, 127, 516, 444, 483, 378, 923, 674, 422, 664, 181, 179, 321, 602}

    Returns: 7938

  19. {479, 551, 232, 301, 509, 100, 609, 306, 76, 110, 261, 260, 200, 792, 318, 539, 148, 572, 230, 384, 294, 31, 517, 831}

    Returns: 5615

  20. {782, 750, 335, 705, 129, 979, 817, 867, 501, 507, 926, 901, 668, 332, 195, 631, 34, 39, 858, 138, 655, 194, 141, 777, 502, 862}

    Returns: 10135

  21. {740, 875, 214, 255, 735, 90, 552, 99, 296, 7, 803, 550, 321, 989, 552, 656, 25, 554, 843, 693, 225, 290, 541, 719, 105, 391, 338, 894}

    Returns: 10737

  22. {218, 250, 956, 746, 635, 430, 962, 113, 267, 907, 649, 333, 217, 952, 481, 142, 588, 821, 268, 586, 416, 357, 787, 856, 587, 15, 245, 433, 616, 814}

    Returns: 12012

  23. {439, 796, 413, 281, 807, 919, 810, 574, 2, 279, 805, 774, 829, 524, 794, 264, 546, 202, 737, 626, 450, 365, 506, 873, 337, 807, 268, 579, 988, 7, 160, 352}

    Returns: 14369

  24. {670, 678, 231, 581, 43, 117, 816, 856, 638, 419, 676, 869, 52, 205, 861, 346, 630, 85, 937, 350, 20, 474, 790, 293, 243, 103, 323, 108, 247, 33, 534, 870, 81, 805}

    Returns: 12214

  25. {88, 27, 368, 476, 88, 852, 874, 282, 614, 659, 530, 846, 127, 630, 241, 57, 697, 730, 373, 790, 692, 310, 440, 667, 23, 258, 101, 489, 18, 238, 229, 418, 993, 529, 405, 745}

    Returns: 14959

  26. {287, 405, 750, 328, 794, 82, 131, 370, 832, 244, 155, 304, 23, 852, 951, 677, 493, 929, 550, 904, 477, 300, 230, 672, 6, 707, 748, 594, 60, 672, 43, 477, 447, 177, 763, 530, 544, 452}

    Returns: 15591

  27. {45, 424, 641, 650, 217, 478, 939, 983, 702, 325, 928, 600, 213, 747, 821, 801, 215, 608, 71, 745, 880, 917, 652, 40, 700, 643, 712, 365, 589, 712, 984, 57, 273, 871, 854, 37, 862, 473, 203, 652}

    Returns: 20929

  28. {867, 885, 624, 54, 867, 201, 803, 670, 250, 226, 599, 942, 95, 937, 906, 57, 796, 762, 784, 882, 664, 39, 872, 162, 669, 650, 417, 79, 926, 84, 770, 823, 632, 50, 218, 190, 152, 142, 147, 888, 374, 0}

    Returns: 17045

  29. {689, 698, 496, 970, 538, 153, 880, 81, 368, 602, 818, 861, 484, 783, 291, 108, 784, 166, 906, 753, 681, 770, 749, 128, 121, 930, 518, 68, 846, 726, 123, 391, 842, 325, 498, 831, 741, 236, 798, 672, 542, 19, 391, 327}

    Returns: 17901

  30. {370, 74, 378, 939, 990, 843, 38, 556, 577, 218, 172, 119, 808, 111, 849, 888, 733, 574, 476, 820, 201, 938, 633, 522, 492, 642, 857, 179, 595, 761, 938, 437, 183, 64, 387, 953, 864, 718, 325, 111, 852, 709, 28, 127, 68, 152}

    Returns: 21049

  31. {78, 653, 56, 299, 348, 830, 78, 243, 163, 931, 354, 389, 215, 653, 373, 672, 13, 785, 573, 649, 369, 817, 206, 104, 473, 433, 436, 21, 435, 905, 420, 699, 14, 921, 896, 721, 842, 450, 318, 236, 966, 19, 403, 560, 613, 259, 653, 754}

    Returns: 20942

  32. {978, 599, 991, 768, 170, 384, 706, 260, 445, 585, 743, 520, 172, 60, 422, 89, 267, 375, 477, 741, 782, 517, 951, 263, 277, 502, 402, 440, 888, 145, 85, 599, 711, 974, 113, 523, 878, 81, 495, 294, 524, 67, 444, 77, 633, 767, 731, 730, 918, 493}

    Returns: 18531

  33. {0, 0}

    Returns: 0

  34. {1000, 1000}

    Returns: 0

  35. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}

    Returns: 0

  36. {1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000}

    Returns: 0

  37. {712, 745, 230, 200, 648, 440, 115, 913, 627, 621, 186, 222, 741, 954, 581, 193, 266, 320, 798, 745 }

    Returns: 6393

  38. {10, 50, 30, 5, 10, 100, 1 }

    Returns: 160

  39. {1, 3, 2, 0 }

    Returns: 3

  40. {5, 7, 10 }

    Returns: 7

  41. {6, 8, 5, 4, 7, 4, 2, 3, 1 }

    Returns: 6

  42. {30, 31 }

    Returns: 1

  43. {2, 3, 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: