Statistics

Problem Statement for "ElevatorLimit"

Problem Statement

Often the maintenance staff of a large building wants to verify that the elevator in the building is being used appropriately. The manufacturer designates safety limits regarding the maximum number of people that should be on the elevator at the same time. Also, there is a physical limitation as to how many people can actually be in the elevator simultaneously. The building in question has very primitive sensing equipment, and only has data telling how many people entered and exited on a particular stop. That is, the data does not explicitly state how many people were on the elevator at any given point in time.

You are to write a class ElevatorLimit, with a method getRange, which takes as parameters a int[] enter, a int[] exit, and an int physicalLimit, where the ith element in each int[] indicates the number of people that entered and exited, respectively, the elevator on the ith stop. At each stop people exit the elevator first, and then people enter. physicalLimit is how many people are physically capable of being in the elevator simultaneously. You are to determine the maximum and minimum numbers of people that could have been on the elevator before the simulation begins, and return these values in a int[] containing exactly two elements. The first element of the return value is the minimum, and the second element is the maximum number.

If the data entered yields an impossible situation, you are to return an empty int[].

Definition

Class:
ElevatorLimit
Method:
getRange
Parameters:
int[], int[], int
Returns:
int[]
Method signature:
int[] getRange(int[] enter, int[] exit, int physicalLimit)
(be sure your method is public)

Constraints

  • enter and exit will have between 1 and 50 elements, inclusive.
  • enter and exit will have the same number of elements.
  • Each element of enter and exit will be between 0 and 1000, inclusive.
  • physicalLimit will be between 1 and 1000, inclusive.

Examples

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

    {5,4,3,2,1}

    25

    Returns: { 9, 25 }

  2. {1,0}

    {0,1}

    1

    Returns: { 0, 0 }

    With a physicalLimit of one person on the elevator at a time, there had to be 0 to start with.

  3. {1,0}

    {0,1}

    2

    Returns: { 0, 1 }

    With a physicalLimit of 2 people, the elevator could have started with 0 or 1 people on it.

  4. {0,1}

    {1,0}

    1

    Returns: { 1, 1 }

  5. {0,2}

    {1,0}

    1

    Returns: { }

    Since there is only a maximum of 1 person, 2 people cannot get on at the second stop. Therefore, there is no possible solution.

  6. {54, 127, 157, 39, 29, 156, 192, 60, 51, 156, 79, 175, 112, 109, 180, 3, 24, 63, 133, 100, 136, 40, 114, 98, 199, 82, 15, 105, 49, 40, 33, 193, 116, 32, 59, 177, 152, 35, 5, 30, 190, 158, 12}

    {54, 127, 157, 39, 29, 156, 192, 60, 51, 156, 79, 175, 112, 109, 180, 3, 24, 63, 133, 100, 136, 40, 114, 98, 199, 82, 15, 105, 49, 40, 33, 193, 116, 32, 59, 177, 152, 35, 5, 30, 190, 158, 12}

    558

    Returns: { 199, 558 }

  7. {175, 50, 167, 45, 62, 96, 197, 103, 140, 75, 8, 113, 68, 64, 56, 2, 31, 23, 15, 85, 17, 54, 149, 198, 97}

    {38, 154, 83, 138, 59, 160, 52, 20, 184, 198, 40, 138, 44, 155, 42, 144, 28, 127, 128, 90, 193, 100, 94, 18, 132}

    367

    Returns: { }

  8. {6, 85, 106, 1, 199, 76, 162, 141}

    {38, 68, 62, 83, 170, 12, 61, 114}

    668

    Returns: { 223, 500 }

  9. {159, 41, 182, 81, 7, 35, 168, 63, 131, 193, 107, 179, 105, 159, 52, 110, 61, 70, 25, 199, 179, 47, 22, 97, 112, 196, 183, 32, 182, 109, 52, 176, 64, 86, 57, 143, 146, 18, 138, 101, 81, 197, 13, 38, 166, 125, 54, 59, 44}

    {146, 10, 87, 92, 58, 184, 116, 84, 123, 109, 2, 198, 164, 198, 187, 11, 34, 131, 120, 102, 140, 193, 15, 174, 44, 44, 173, 44, 48, 67, 194, 36, 96, 8, 59, 155, 77, 71, 3, 148, 26, 36, 36, 51, 141, 100, 24, 63, 48}

    900

    Returns: { 303, 318 }

  10. {107, 15, 98, 153, 4, 19, 9, 160, 197, 122, 175, 37, 2, 190, 86, 86, 101, 128, 14, 154, 155, 2, 188, 179, 180, 66, 80}

    {37, 176, 192, 99, 173, 113, 46, 20, 81, 108, 154, 161, 50, 156, 81, 56, 92, 161, 39, 189, 22, 131, 142, 144, 95, 162, 131}

    1

    Returns: { }

  11. {179, 135, 104, 90, 97, 186, 187, 47, 152, 100, 119, 28, 193, 11, 103, 100, 179, 11, 80, 163, 50, 131, 103, 50, 142, 51, 112, 62, 69, 72, 88, 3, 162, 93, 190, 85, 79, 86, 146, 71, 65, 131, 179, 119, 66, 111}

    {134, 81, 178, 168, 86, 128, 1, 165, 62, 46, 188, 70, 104, 111, 3, 47, 144, 69, 163, 21, 101, 126, 169, 84, 146, 165, 198, 1, 65, 181, 135, 99, 100, 195, 171, 47, 16, 54, 79, 69, 6, 97, 154, 80, 151, 76}

    954

    Returns: { 453, 659 }

  12. {35, 125, 84, 47, 176, 71, 141, 46, 12, 174, 126, 14, 4, 58, 179, 161, 173, 148, 157, 175, 30, 53, 98, 99, 3, 100, 95, 174, 189, 23, 106, 101, 135, 70, 97, 156, 54, 156}

    {199, 189, 136, 29, 8, 190, 108, 111, 46, 161, 174, 188, 49, 195, 66, 177, 147, 196, 30, 76, 178, 99, 104, 160, 114, 86, 63, 92, 66, 110, 82, 192, 104, 62, 71, 52, 76, 181}

    785

    Returns: { }

  13. {165, 161, 30, 178, 178, 5, 28, 20, 159, 143, 28}

    {53, 113, 16, 148, 148, 63, 178, 110, 129, 160, 75}

    859

    Returns: { 194, 625 }

  14. {25, 163, 53, 29, 179, 81, 67, 23}

    {37, 161, 31, 137, 160, 162, 166, 159}

    163

    Returns: { }

  15. {164, 45, 153, 127, 141, 101, 35, 90, 146, 63, 122, 66, 10, 130, 160, 178, 83, 73, 197, 59, 58, 105, 35, 193, 167, 122, 153, 79, 71}

    {101, 108, 98, 6, 43, 31, 67, 11, 157, 102, 19, 13, 198, 6, 139, 36, 161, 24, 116, 15, 128, 67, 100, 24, 176, 90, 166, 17, 79}

    971

    Returns: { 101, 135 }

  16. {117, 100, 137, 143, 81, 21, 162, 53, 111, 6, 173, 95, 128, 100, 66, 32, 105, 139, 51, 131, 22, 190, 18, 70, 5, 172, 173, 61, 124, 143, 34, 137, 42, 116, 60, 115, 42, 22, 77, 50, 8, 187, 109, 152, 191}

    {35, 151, 93, 80, 19, 97, 75, 6, 30, 41, 74, 125, 111, 98, 15, 187, 83, 156, 139, 84, 155, 16, 98, 142, 40, 83, 156, 178, 153, 29, 75, 181, 77, 188, 125, 181, 103, 77, 148, 77, 171, 190, 71, 38, 66}

    1000

    Returns: { }

  17. {2}

    {3}

    2

    Returns: { }

  18. {696,327,995,748,124,896,472,877,652,850,656,812,978,375,980,187,13,296,243}

    {205,451,195,626,950,99,649,379,54,599,866,313,183,216,153,232,337,114,610}

    955

    Returns: { }

  19. {136,559,970,167,730,628,614,481,238,442,659,108,892,685,849,312,325,331,754,910,567,49,393,385,988,9,14,909,197,255,88,142,805,131,941}

    {464,251,730,523,60,999,435,545,66,608,635,86,605,256,631,257,475,500,819,570,268,431,969,813,390,505,428,298,277,760,769,573,582,315,836}

    235

    Returns: { }

  20. {528,931,787,745,551,781,820,426,353,11,577,391,11,446,949,666,962,206,564,198,619,997,793}

    {699,432,428,379,214,743,123,532,72,473,307,561,685,299,436,825,654,786,915,439,319,591,908}

    563

    Returns: { }

  21. {962,692,801,531,354,198,45,420,911,148,898,563,641,198,689}

    {508,856,860,264,557,250,195,191,218,535,170,272,997,113,421}

    101

    Returns: { }

  22. {269,437,969,989,469,151,132,166,636,1000,658,810,180,855,472,752,38,1,383,327,333,590,805,636,585,896,768,676,206,96,771,364,593,904,405,324,902,23,203,346,794,306,421,185,528,655,413}

    {95,318,84,384,613,229,974,539,423,271,86,597,641,900,7,786,987,455,540,429,50,609,631,758,448,956,278,735,646,955,195,877,475,416,597,730,901,649,578,968,542,223,640,595,268,48,974}

    885

    Returns: { }

  23. {722,668,984,930,131,547,572,205,282,661,82,879,923,955,770,213,449,907,863,964,610,671,867}

    {874,309,206,968,814,18,361,856,240,698,120,302,253,651,751,118,867,534,943,585,754,424,683}

    604

    Returns: { }

  24. {405,428,328,180,331,568,267,682,661,442,434,777,198,215,584,344,196}

    {432,558,117,564,972,980,565,329,379,114,441,109,996,437,925,932,721}

    926

    Returns: { }

  25. {865,360,886,549,325,527}

    {176,289,937,589,755,376}

    966

    Returns: { 177, 206 }

  26. {205,894,306,26,202,803}

    {447,448,464,190,159,518}

    912

    Returns: { 690, 702 }

  27. {611,382,772,313,641,394}

    {316,653,387,417,653,73}

    994

    Returns: { 363, 380 }

  28. {381,330,242,94,92,748,3,435,193,469,290,471,27}

    {355,412,346,75,182,217,68,372,218,612,428,496,570}

    990

    Returns: { 603, 690 }

  29. {136,221,351,404,266,590,6,742,205}

    {41,267,660,189,465,295,119,752,330}

    962

    Returns: { 814, 867 }

  30. {295,752,84,439,607,581}

    {558,664,644,2,564,451}

    948

    Returns: { 927, 948 }

  31. {622,144,607,687,341,138}

    {142,273,657,549,314,451}

    914

    Returns: { 306, 434 }

  32. {111,516,416,45,142,564}

    {273,565,212,264,265,244}

    805

    Returns: { 727, 805 }

  33. {534,369,645,663,542,568}

    {750,515,164,742,794,220}

    993

    Returns: { 754, 857 }

  34. {133,401,321,141,507,324}

    {67,64,62,353,385,545}

    788

    Returns: { 67, 126 }

  35. {113,512,47,818,294,113}

    {63,654,727,143,629,10}

    997

    Returns: { 915, 947 }

  36. {597,148,149,199,643,159,484}

    {61,198,52,897,87,290,151}

    972

    Returns: { 314, 329 }

  37. {323,174,317,716,154,290,510,833}

    {104,64,291,677,251,383,229,657}

    986

    Returns: { 322, 325 }

  38. {351,545,107,262,716,127,353}

    {420,338,117,484,734,30,551}

    985

    Returns: { 828, 847 }

  39. {664,381,329,232,306,646,46,491}

    {76,656,439,183,329,186,178,511}

    921

    Returns: { 126, 232 }

  40. {343,338,471,551,884,22,353}

    {150,187,885,522,475,257,399}

    962

    Returns: { 592, 594 }

  41. {271,142,58,242,187,372}

    {236,131,61,120,247,51}

    844

    Returns: { 236, 418 }

  42. {359,496,161,379,398,200}

    {733,354,227,492,161,170}

    928

    Returns: { 790, 928 }

  43. {602,410,242,615,406,11}

    {618,543,121,713,121,587}

    943

    Returns: { 741, 784 }

  44. {494,365,201,853,302,496,285}

    {372,240,317,517,307,543,733}

    901

    Returns: { 386, 434 }

  45. { 0 }

    { 1000 }

    1000

    Returns: { 1000, 1000 }

  46. { 0, 2 }

    { 1, 0 }

    1

    Returns: { }

  47. { 2, 2, 2 }

    { 0, 0, 0 }

    4

    Returns: { }

  48. { 1, 1 }

    { 3, 3 }

    4

    Returns: { }

  49. { 0 }

    { 1 }

    5

    Returns: { 1, 5 }

  50. { 2 }

    { 3 }

    3

    Returns: { 3, 3 }

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

    { 5, 102, 5, 2, 103, 65, 24, 12, 5, 6, 11, 9 }

    30

    Returns: { }

  52. { 50 }

    { 100 }

    110

    Returns: { 100, 110 }

  53. { 3, 0, 0 }

    { 0, 3, 3 }

    5

    Returns: { }

  54. { 1, 1, 1 }

    { 0, 0, 0 }

    1

    Returns: { }

  55. { 179, 135, 104, 90, 97, 186, 187, 47, 152, 100, 119, 28, 193, 11, 103, 100, 179, 11, 80, 163, 50, 131, 103, 50, 142, 51, 112, 62, 69, 72, 88, 3, 162, 93, 190, 85, 79, 86, 146, 71, 65, 131, 179, 119, 66, 111 }

    { 134, 81, 178, 168, 86, 128, 1, 165, 62, 46, 188, 70, 104, 111, 3, 47, 144, 69, 163, 21, 101, 126, 169, 84, 146, 165, 198, 1, 65, 181, 135, 99, 100, 195, 171, 47, 16, 54, 79, 69, 6, 97, 154, 80, 151, 76 }

    954

    Returns: { 453, 659 }

  56. { 1 }

    { 1 }

    2

    Returns: { 1, 2 }

  57. { 50, 0, 0 }

    { 0, 50, 50 }

    50

    Returns: { }

  58. { 0 }

    { 100 }

    100

    Returns: { 100, 100 }

  59. { 0 }

    { 3 }

    3

    Returns: { 3, 3 }

  60. { 0 }

    { 20 }

    30

    Returns: { 20, 30 }

  61. { 2 }

    { 3 }

    5

    Returns: { 3, 5 }

  62. {1, 0 }

    {0, 3 }

    1

    Returns: { }


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: