Connection Status:
Competition Arena > ElevatorLimit
SRM 201 · 2004-06-29 · by zoidal · Brute Force, Simulation
Class Name: ElevatorLimit
Return Type: int[]
Method Name: getRange
Arg Types: (vector<int>, vector<int>, int)
Problem Statement

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[].

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
0)
{1,2,3,4,5}
{5,4,3,2,1}
25
Returns: { 9,  25 }
1)
{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.

2)
{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.

3)
{0,1}
{1,0}
1
Returns: { 1,  1 }
4)
{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.

Submissions are judged against all 62 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class ElevatorLimit with a public method vector<int> getRange(vector<int> enter, vector<int> exit, int physicalLimit) · 62 test cases · 2 s / 256 MB per case

Submitting as anonymous