Statistics

Problem Statement for "StreetWalking"

Problem Statement

You are walking home from school through the city. 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 are trying to get to your home, located at (X, Y). You have two methods of travel available to you: you can walk along the street to proceed to a horizontally or vertically adjacent intersection (which takes walkTime seconds), or you can sneak across the block diagonally to the opposite corner (taking sneakTime seconds). You can walk or sneak in any of the eight directions shown in the image (see example 2).



Return the least amount of time that it will take you to return home. See the examples for clarification.

Definition

Class:
StreetWalking
Method:
minTime
Parameters:
int, int, int, int
Returns:
long
Method signature:
long minTime(int X, int Y, int walkTime, int sneakTime)
(be sure your method is public)

Constraints

  • X will be between 0 and 1,000,000,000, inclusive.
  • Y will be between 0 and 1,000,000,000, inclusive.
  • walkTime will be between 1 and 10000, inclusive.
  • sneakTime will be between 1 and 10000, inclusive.

Examples

  1. 4

    2

    3

    10

    Returns: 18

    The fastest way to your home is to not sneak at all.

  2. 4

    2

    3

    5

    Returns: 16

    In this case, it is faster to sneak across twice, following the path (0,0)->(1,0)->(2,1)->(3,1)->(4,2). This takes 10 seconds for the sneaking, and 6 seconds for the walking.

  3. 2

    0

    12

    10

    Returns: 20

    One possible path is (0,0)->(1,1)->(2,0).

  4. 1000000

    1000000

    1000

    1000

    Returns: 1000000000

    Formerly the maximal return

  5. 0

    0

    12

    25

    Returns: 0

    Minimal return

  6. 25

    18

    7

    11

    Returns: 247

  7. 25

    18

    7

    6

    Returns: 151

  8. 24

    16

    12

    10

    Returns: 240

  9. 1000000000

    1000000000

    10000

    10000

    Returns: 10000000000000

    New maximum return.

  10. 37

    18

    12

    25

    Returns: 660

  11. 53437378

    43542123

    37

    12

    Returns: 641248561

  12. 453543573

    453573787

    1234

    6789

    Returns: 1119382822240

  13. 453543573

    453573787

    6789

    1234

    Returns: 559710053158

  14. 453543573

    453573787

    6789

    7890

    Returns: 3578663913816

  15. 239458

    23535

    10

    1

    Returns: 239467

  16. 239458

    23535

    10

    15

    Returns: 2512255

  17. 239458

    23535

    10

    30

    Returns: 2629930

  18. 23

    131351355

    249

    302

    Returns: 32706488614

  19. 123

    456

    78

    90

    Returns: 37044

    The numbers look cool here :)

  20. 398527359

    0

    40

    20

    Returns: 7970547200

  21. 0

    398527359

    15

    40

    Returns: 5977910385

  22. 0

    0

    10000

    10000

    Returns: 0

  23. 1000000000

    0

    10000

    8000

    Returns: 8000000000000

  24. 0

    1000000000

    10000

    7000

    Returns: 7000000000000

  25. 1000000000

    50000

    1000

    1500

    Returns: 1000025000000

  26. 50000

    1000000000

    1000

    2001

    Returns: 1000050000000

  27. 1000000000

    50000

    1000

    666

    Returns: 666000000000

  28. 50001

    1000000000

    1000

    666

    Returns: 666000000334

  29. 1000000000

    50001

    1000

    665

    Returns: 665000000335

  30. 125

    472

    1

    2

    Returns: 597

  31. 10000000

    50000000

    800

    901

    Returns: 41010000000

  32. 135

    122

    43

    29

    Returns: 3929

  33. 3445333

    545437122

    345

    354

    Returns: 188206815087

  34. 100000000

    100000000

    2

    2

    Returns: 200000000

  35. 10000000

    5

    123

    122

    Returns: 1220000001

  36. 125

    122313000

    123

    344

    Returns: 15044514375

  37. 214748364

    214748365

    8

    10

    Returns: 2147483648

  38. 214748364

    214748365

    7

    10

    Returns: 2147483647

  39. 343454353

    0

    951

    950

    Returns: 326281635351

  40. 999999999

    0

    1000

    1

    Returns: 1000000998

  41. 1

    1

    4

    6

    Returns: 6

  42. 100

    100

    100

    100

    Returns: 10000

  43. 1000000000

    999999997

    4999

    10000

    Returns: 9997999985003

  44. 1

    1

    1

    100

    Returns: 2

  45. 2

    3

    3

    4

    Returns: 11

  46. 1000000000

    1000000000

    4999

    9999

    Returns: 9998000000000

  47. 2

    1

    100

    10

    Returns: 110

  48. 11234

    3214

    100

    3

    Returns: 33702

  49. 1000000000

    1000000000

    1

    10

    Returns: 2000000000

  50. 10000000

    9758463

    11

    12

    Returns: 119758463

  51. 932859771

    1000000000

    9835

    5431

    Returns: 5431000004404

  52. 1

    2

    5

    3

    Returns: 8

  53. 2

    2

    10

    100

    Returns: 40

  54. 1000000000

    0

    10000

    9999

    Returns: 9999000000000

  55. 1000000000

    1000000000

    10000

    50

    Returns: 50000000000

  56. 999999999

    999999997

    5

    7

    Returns: 6999999989

  57. 1000000000

    999999999

    324

    1000

    Returns: 647999999676

  58. 999999999

    899899899

    98

    76

    Returns: 75999999924

  59. 10000000

    9758463

    50

    12

    Returns: 120000038

  60. 3

    5

    100

    1

    Returns: 5

  61. 1000000000

    1000000000

    499

    1000

    Returns: 998000000000

  62. 1

    2

    1000

    1

    Returns: 1001

  63. 136

    123

    43

    29

    Returns: 3958

  64. 1000000000

    1000000000

    1

    1

    Returns: 1000000000

  65. 1000000000

    1000000000

    400

    1000

    Returns: 800000000000

  66. 100000000

    100000000

    10000

    10000

    Returns: 1000000000000

  67. 1

    3

    296

    300

    Returns: 892

  68. 7

    7

    10

    2

    Returns: 14

  69. 3

    1

    100

    1

    Returns: 3

  70. 1000000000

    1000000000

    5

    20

    Returns: 10000000000

  71. 100000

    1

    10000

    1

    Returns: 109999

  72. 0

    5

    100

    99

    Returns: 496

  73. 1000000000

    1000000000

    4999

    10000

    Returns: 9998000000000

  74. 1000000000

    1000000000

    10000

    9999

    Returns: 9999000000000

  75. 0

    0

    10

    1000

    Returns: 0

  76. 30

    10

    10

    30

    Returns: 400

  77. 135

    122

    60

    29

    Returns: 3946

  78. 1000000000

    1000000000

    1000

    2000

    Returns: 2000000000000

  79. 999

    988

    100

    10000

    Returns: 198700

  80. 5

    1

    3

    2

    Returns: 10

  81. 1000000000

    1000000000

    1000

    10000

    Returns: 2000000000000

  82. 1000000000

    1000000000

    1000

    3000

    Returns: 2000000000000

  83. 1

    1

    10

    90

    Returns: 20

  84. 3

    0

    3

    2

    Returns: 7

  85. 2

    1

    5

    2

    Returns: 7

  86. 1000000000

    1000000000

    5000

    10000

    Returns: 10000000000000

  87. 1

    1

    15

    10

    Returns: 10

  88. 1000000000

    1000000000

    10000

    1

    Returns: 1000000000

  89. 7

    1

    4

    3

    Returns: 21

  90. 3

    0

    10

    100

    Returns: 30

  91. 100

    100

    24

    50

    Returns: 4800


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: