ElevatorLimit
SRM 201 · 2004-06-29 · by zoidal
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
If the data entered yields an impossible situation, you are to return an empty
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.
{1,2,3,4,5}
{5,4,3,2,1}
25
Returns: { 9, 25 }
{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.
{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.
{0,1}
{1,0}
1
Returns: { 1, 1 }
{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.
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