TopCoder problem "GrabbingTaxi" used in SRM 400 (Division II Level One)



Problem Statement

    

You are walking in the city on a holiday. Suddenly, you are told to go to your office as soon as possible by your boss via cell phone. The city is infinite in size, with vertical streets located at every integer X value and horizontal streets located at every Y value. You are currently located at (0, 0) and your office is located at (gX, gY). There are some taxi stands in the city and their locations are (tXs[i], tYs[i]). You can either go to the office by foot or go to some taxi stand, get a taxi there and go to the office by taxi. It takes walkTime seconds to go along the street to proceed to a horizontally or vertically adjacent intersection by foot and it takes taxiTime seconds by a taxi.

Return the least amount of time that it will take you to go to your office.

 

Definition

    
Class:GrabbingTaxi
Method:minTime
Parameters:int[], int[], int, int, int, int
Returns:int
Method signature:int minTime(int[] tXs, int[] tYs, int gX, int gY, int walkTime, int taxiTime)
(be sure your method is public)
    
 

Constraints

-tXs will contain between 0 and 50 elements, inclusive.
-tXs and tYs will contain the same number of elements.
-Each element of tXs and tYs will be between -10000 and 10000, inclusive.
-gX and gY will be between -10000 and 10000, inclusive.
-walkTime and taxiTime will be between 1 and 1000, inclusive.
 

Examples

0)
    
{}
{}
3
2
10
2
Returns: 50
There are no taxi stands. You have to walk to the goal.
1)
    
{-2, -2}
{0, -2}
-4
-2
15
3
Returns: 42
First, you walk to (-2, 0) and get a taxi. Then you go to the goal by it.
2)
    
{3}
{0}
5
0
10
20
Returns: 50
taxiTime may be larger than walkTime.
3)
    
{34, -12, 1, 0, 21, -43, -98, 11, 86, -31}
{11, 5, -68, 69, -78, -49, -36, -2, 1, 70}
-97
-39
47
13
Returns: 2476
4)
    
{82, -60, 57, 98, 30, -67, 84, -42, -100, 62}
{-7, 90, 53, -56, -15, -87, 22, -3, -61, -30}
21
15
53
2
Returns: 1908

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=8753

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=12172&pm=8753

Writer:

ymatsu

Testers:

PabloGilberto , Andrew_Lazarev , ivan_metelsky

Problem categories:

Simple Search, Iteration