TopcoderArchiveVisit Topcoder
Archive
Algorithm problem

EMS

Problem statement, definition, constraints, and public examples.

Problem Statement

PROBLEM STATEMENT

When a call for a medical emergency reaches a city or county's 911 system,
dispatchers generally send out a fire engine and an ambulance.  In many
counties, the ambulance service is a privately owned company, and not part of
the fire department.  You are the dispatcher for Happyville's 911 ambulance
provider company.  When a call comes in, you need to be able to figure out
which ambulance is your closest unit.  Given the two nearest ambulances, you
must figure out the quickest that one of them can get to the scene of the
emergency.  The rules are as follows: each ambulance is a certain number of
blocks away.  Since they can go at Code 3 (lights and sirens), traffic is not
an issue (since people ALWAYS pull over).  However, at each intersection, the
ambulance has to stop for safety, based on the following rules:

*If there is a stop sign at the intersection, the ambulance must stop.  Since
this can usually be accomplished with a California rolling-stop, this delays
the ambulance 3 seconds.
*If there is a red traffic light, the ambulance must make a serious stop.
Since, according to Murphy's law, the light will always be red, any traffic
light adds 5 seconds to the trip.
*If there is an uncontrolled intersection (no stop sign or traffic light),
there is no delay.

Each block takes 10 seconds to navigate.

Given a int[] of intersections:
0 - uncontrolled
1 - stop sign
2 - traffic light

Calculate the response time for each ambulance and return the smaller one.

You can assume the ambulance travels as many blocks as intersections.

DEFINITION

Class name: EMS
Method name: minResponseTime
Parameters: int[], int[]
Returns: int
The method signature is:
int minResponseTime(int[] rig1, int[] rig2)
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:
*rig1 and rig2 contain between 1 and 10 elements, inclusive
*each element of rig1 and rig2 must be an integer value of 0, 1, or 2

EXAMPLES

rig1 = {0,0,0,0}
rig2 = {1,2,2}

Since rig1 has a response time of 4 * 10 = 40 seconds, and rig2 has a response
time of 3 * 10 + 3 + 5 + 5 = 43 seconds, rig1 is faster even though it is more
blocks away.
The method returns 40.

rig1 = {0,1,1,0,2,2,1}
rig2 = {2,2,0,0,0,2,2}
return = 89

rig1 = {2,2,2}
rig2 = {0,0,0,0}
return = 40

rig1 = {1,0,2}
rig2 = {1,1,1,0}
return = 38

Definition

Class:
EMS
Method:
minResponseTime
Parameters:
int[], int[]
Returns:
int
Method signature:
int minResponseTime(int[] param0, int[] param1)
(be sure your method is public)

Constraints

    Examples

      No public sample cases were explicitly marked for this problem in the original data.

      Back to all problems