Problem Statement
PROBLEM STATEMENT
When an MCI, or multiple-casualty incident occurs, one or more ambulances must
be dispatched to help treat and transport the wounded. In reality, and MCI is
often defined as a situation where the initial response team has too many
patients to handle. For the purposes of this problem, we will define it as any
situation with 2 or more patients. There are two types of ambulance available
when an MCI occurs:
BLS is a basic life support rig and can only transport one of the following
combinations of patients:
2 delayed
1 delayed, 3 minor
6 minor
ALS is and advanced life support car with at least one paramedic on board, and
can transport the following combinations in addition to those that a BLS car
can transport:
1 immediate, 1 delayed
1 immediate, 2 minor
Since the dispatchers can't be sure how many more are needed before all the
patients are cleared out, the closest units will always be the ones responding.
There will never be an ambulance dispatched without all the ambulances closer
to the scene dispatched as well. This means that you could potentially have
more ambulances than necessary if one or more BLS rigs respond before an ALS
unit that is further out (see example 2). However, once there are enough
ambulances of the correct type present to transport all patients, no more
ambulances should be dispatched. So in essence, you are to dispatch the
minimum number of ambulances, with the exception of the distance rule mentioned
above.
A rig does not have to be completely filled. In fact, it can be empty, in the
case of a BLS rig dispatched before and ALS rig for an immediate patient (see
example 3).
Given a number of patients and a list of ambulances units and their distances
from the MCI, you are to return a int[] of the unit numbers that need to
respond to the scene in order to be able to transport all of the patients to a
nearby hospital.
The ambulances will be specified in a String[], formatted as follows:
"TYPE #UNIT:DISTANCE"
where type is "BLS" or "ALS", UNIT is the unit number, and DISTANCE is the
distance from the scene of the MCI.
DEFINITION
Class name: MCI
Method name: dispatchUnits
Parameters: String[], int, int, int
Returns: int[]
The method signature is:
int[] dispatchUnits(String[] units, int minor, int delayed, int immediate)
Be sure your method is public.
TopCoder will ensure the validity of the inputs. Inputs are valid if all of
the following
criteria are met:
*units will contain between 2 and 20 members, inclusive
*each element of units will be a string formatted as "TYPE #UNIT:DISTANCE"
*type will be either "BLS" or "ALS"
*unit number will be an integer ranging from 1 to 1000, inclusive
*distance from MCI will be an integer ranging from 0 to 20. inclusive
*no two units will have the same unit number
*minor, delayed, and immediate will all contain an integer between 0 and 10,
and their total will be no less than 2
If multiple rigs are available at the same distance, choose them so the least
number of ALS rigs must be sent out. If there are multiple units of the same
type that must be sent out from a given distance, dispatch them in increasing
unit order. See the final examples below.
If ALS units must be dispatched anyway, and can handle the patients without
additional BLS help, do not dispatch any additional BLS units (except the ones
that are closer to incident, and therefore are dispatched by the distance
rule). See examples 5 and 6 to illustrate this point.
If there are not enough ambulances to transport all patients, dispatch all
units anyway!
Your returned should be ordered numerically by unit.
EXAMPLES
units =
{"BLS #446:2",
"ALS #134:4",
"BLS #445:6"}
minor = 3
delayed = 2
immediate = 1
BLS #446 can take 1 delayed and 3 minors, and ALS #134 can take the immediate
and the other delayed. The function should return {134, 446}
units =
{"BLS #10:2",
"ALS #13:3",
"ALS #42:5"}
minor = 2
delayed = 0
immediate = 1
ALS #13 can handle all 3 patients, but since BLS #10 is closer, they are both
dispatched. Therefore the function returns {10, 13}
units =
{"BLS #10:2",
"ALS #13:3",
"ALS #42:5"}
minor = 0
delayed = 0
immediate = 2
Although it means BLS #10 will be empty, it must be dispatched since it is
closer than the two ALS rigs necessary. The function returns {10,13,42}.
units =
{"ALS #100:1",
"ALS #200:2",
"ALS #300:3"}
minor = 2
delayed = 2
immediate = 4
Even though all three units couldn't transport all four of the immediate
patients, all three are dispatched.
the function returns {100, 200, 300}
units =
{"BLS #1:2",
"ALS #2:2"}
minor = 3
delayed = 1
immediate = 0
Since the BLS unit can handle the call, the function returns {1}
units =
{"BLS #1:2",
"ALS #2:2"}
minor = 2
delayed = 0
immediate = 1
Since the ALS unit is required for the immediate and can handle the 2 minors as
well, the function returns {2}
units =
{"BLS #10:1",
"BLS #20:2",
"ALS #21:2",
"BLS #22:2",
"ALS #30:3",
"ALS #31:3"}
minor = 6
delayed = 3
immediate = 2
Two ALS rigs are needed, so everything at a distance of 1 or 2 is sent, as well
as the first rig (numerically) at distance 3. The functions should return
{10,20,21,22,30}
Definition
- Class:
- MCI
- Method:
- dispatchUnits
- Parameters:
- String[], int, int, int
- Returns:
- int[]
- Method signature:
- int[] dispatchUnits(String[] param0, int param1, int param2, int param3)
- (be sure your method is public)
Constraints
Examples
No public sample cases were explicitly marked for this problem in the original data.