Statistics

Problem Statement for "WatchedSnail"

Problem Statement

A snail was racing along a straight trail for raceTime seconds. The snail maintained the same direction during the entire race. On the other hand, its speed during the race was not necessarily constant.


The race had observerCount observers. Each of them watched the snail during a single contiguous closed interval that measured exactly observationTime seconds.

(No observation started before the start of the race. No observation ended after the end of the race. Some observers could have started and therefore also ended their observation at a non-integer timestamp.)

It is guaranteed that during the entire race the snail was always observed by at least one person. Each observer came to the same conclusion: the distance traveled by the snail during their observation was exactly observationDistance inches.


Return the maximum distance in inches the snail could have traveled during the entire race.

Definition

Class:
WatchedSnail
Method:
maxDistance
Parameters:
int, int, int, int
Returns:
double
Method signature:
double maxDistance(int raceTime, int observerCount, int observationTime, int observationDistance)
(be sure your method is public)

Notes

  • Your return value will be accepted if it has an absolute or a relative error at most 10^(-9).
  • The snail cannot teleport (move at infinite speed). Its position in time is a continuous non-decreasing function.
  • As implied by the "non-decreasing" in the previous sentence, the snail may stand still during some intervals of time.

Constraints

  • raceTime will be between 1 and 1000, inclusive.
  • observerCount will be between 1 and 1000, inclusive.
  • observationTime will be between 1 and raceTime, inclusive.
  • observationDistance will be between 1 and 1000, inclusive.
  • observerCount * observationTime will be greater than or equal to raceTime.

Examples

  1. 100

    3

    100

    47

    Returns: 47.0

    Each person observed the snail during the entire race and saw the snail traverse 47 inches.

  2. 100

    10

    10

    47

    Returns: 470.0

    Ten people took turns watching the snail. Each person saw the snail traverse 47 inches, so the snail traversed 470 inches total. Boring.

  3. 100

    8

    20

    47

    Returns: 376.0

    This should be obvious, right? Each observation took 20 seconds. The distance traveled during each observation is 47 inches, so for each observation the snail had an average speed of 2.35 inches per second. The whole race was 100 seconds and at that average speed the snail must have travelled 2.35 * 100 = 235 inches. The snail was always watched, so it could not have... wait, what?

  4. 100

    2

    74

    47

    Returns: 94.0

    One observer started at the beginning of the race and one ended at the end of the race. If [0,100] is the time interval of the race, the first observer was active during [0,74] and the second one during [26,100]. It is possible that the snail traversed only 47 inches total, but it is also possible that it traversed more. The largest possible total distance it could have travelled is obviously 94 inches. The answer would clearly remain 94 inches even if we had more than two observers (while keeping the other three parameters the same).

  5. 60

    47

    10

    10

    Returns: 100.0

  6. 60

    7

    10

    10

    Returns: 70.0

  7. 6

    2

    4

    567

    Returns: 1134.0

  8. 8

    10

    6

    264

    Returns: 528.0

  9. 9

    7

    7

    631

    Returns: 1262.0

  10. 1

    7

    1

    981

    Returns: 981.0

  11. 2

    1

    2

    966

    Returns: 966.0

  12. 8

    9

    1

    940

    Returns: 8460.0

  13. 6

    10

    4

    236

    Returns: 472.0

  14. 4

    9

    3

    453

    Returns: 906.0

  15. 6

    10

    3

    572

    Returns: 1144.0

  16. 10

    4

    4

    808

    Returns: 3232.0

  17. 1

    3

    1

    101

    Returns: 101.0

  18. 6

    10

    4

    521

    Returns: 1042.0

  19. 9

    5

    2

    665

    Returns: 3325.0

  20. 4

    6

    2

    483

    Returns: 966.0

  21. 2

    7

    2

    692

    Returns: 692.0

  22. 5

    4

    5

    945

    Returns: 945.0

  23. 5

    6

    5

    579

    Returns: 579.0

  24. 1

    8

    1

    577

    Returns: 577.0

  25. 7

    5

    6

    532

    Returns: 1064.0

  26. 4

    10

    1

    643

    Returns: 3858.0

  27. 4

    7

    4

    260

    Returns: 260.0

  28. 10

    9

    3

    455

    Returns: 2730.0

  29. 1

    3

    1

    77

    Returns: 77.0

  30. 5

    9

    5

    560

    Returns: 560.0

  31. 8

    7

    6

    941

    Returns: 1882.0

  32. 1

    10

    1

    921

    Returns: 921.0

  33. 10

    9

    8

    937

    Returns: 1874.0

  34. 6

    1

    6

    249

    Returns: 249.0

  35. 4

    6

    4

    982

    Returns: 982.0

  36. 43

    19

    27

    541

    Returns: 1082.0

  37. 483

    1

    483

    144

    Returns: 144.0

  38. 63

    127

    5

    856

    Returns: 20544.0

  39. 26

    2

    13

    127

    Returns: 254.0

  40. 1

    567

    1

    830

    Returns: 830.0

  41. 218

    268

    15

    551

    Returns: 15428.0

  42. 4

    9

    1

    433

    Returns: 2598.0

  43. 616

    638

    59

    345

    Returns: 6900.0

  44. 195

    43

    5

    473

    Returns: 20339.0

  45. 14

    9

    5

    972

    Returns: 3888.0

  46. 12

    628

    1

    624

    Returns: 13728.0

  47. 223

    13

    25

    605

    Returns: 7865.0

  48. 11

    37

    5

    604

    Returns: 2416.0

  49. 14

    736

    2

    831

    Returns: 9972.0

  50. 1

    15

    1

    334

    Returns: 334.0

  51. 21

    586

    3

    46

    Returns: 552.0

  52. 432

    91

    22

    988

    Returns: 37544.0

  53. 818

    279

    197

    416

    Returns: 3328.0

  54. 2

    7

    1

    22

    Returns: 44.0

  55. 561

    2

    375

    990

    Returns: 1980.0

  56. 458

    2

    333

    475

    Returns: 950.0

  57. 6

    14

    1

    130

    Returns: 1300.0

  58. 4

    28

    4

    605

    Returns: 605.0

  59. 160

    4

    40

    531

    Returns: 2124.0

  60. 25

    41

    25

    632

    Returns: 632.0

  61. 1

    915

    1

    360

    Returns: 360.0

  62. 34

    387

    11

    925

    Returns: 5550.0

  63. 46

    763

    27

    115

    Returns: 230.0

  64. 21

    138

    3

    335

    Returns: 4020.0

  65. 304

    22

    15

    567

    Returns: 12474.0

  66. 768

    968

    21

    904

    Returns: 65088.0

  67. 431

    304

    3

    628

    Returns: 179608.0

  68. 89

    7

    13

    109

    Returns: 763.0

  69. 233

    75

    92

    562

    Returns: 2248.0

  70. 7

    834

    6

    466

    Returns: 932.0

  71. 79

    6

    14

    469

    Returns: 2814.0

  72. 838

    94

    12

    712

    Returns: 66928.0

  73. 107

    42

    3

    476

    Returns: 19992.0

  74. 118

    6

    117

    10

    Returns: 20.0

  75. 792

    2

    428

    454

    Returns: 908.0

  76. 47

    3

    47

    283

    Returns: 283.0

  77. 193

    136

    23

    706

    Returns: 11296.0

  78. 336

    440

    21

    81

    Returns: 2430.0

  79. 35

    554

    7

    283

    Returns: 2264.0

  80. 12

    127

    1

    938

    Returns: 20636.0

  81. 67

    505

    1

    652

    Returns: 86064.0

  82. 230

    43

    104

    625

    Returns: 2500.0

  83. 303

    747

    3

    952

    Returns: 190400.0

  84. 753

    979

    43

    568

    Returns: 19312.0

  85. 666

    42

    42

    13

    Returns: 390.0

  86. 10

    3

    9

    1

    Returns: 2.0

  87. 913

    200

    10

    100

    Returns: 18200.0

  88. 1000

    1000

    100

    100

    Returns: 1800.0

  89. 100

    20

    10

    1

    Returns: 18.0

  90. 10

    3

    5

    1

    Returns: 2.0

  91. 100

    100

    20

    47

    Returns: 376.0

  92. 2

    1000

    1

    1000

    Returns: 2000.0

  93. 8

    100

    2

    8

    Returns: 48.0

  94. 100

    100

    3

    40

    Returns: 2640.0

  95. 100

    3

    74

    47

    Returns: 94.0

  96. 200

    3

    100

    47

    Returns: 94.0

  97. 101

    3

    100

    47

    Returns: 94.0

  98. 100

    1000

    50

    47

    Returns: 94.0

  99. 101

    100

    20

    47

    Returns: 470.0

  100. 1000

    1000

    300

    1

    Returns: 6.0

  101. 100

    13

    20

    47

    Returns: 376.0

  102. 8

    25

    3

    10

    Returns: 40.0

  103. 100

    100

    20

    100

    Returns: 800.0

  104. 10

    100

    2

    1

    Returns: 8.0

  105. 201

    1000

    100

    1

    Returns: 4.0

  106. 100

    23

    70

    49

    Returns: 98.0

  107. 100

    20

    21

    47

    Returns: 376.0

  108. 3

    10

    1

    1

    Returns: 4.0

  109. 8

    8

    2

    9

    Returns: 54.0

  110. 120

    30

    7

    10

    Returns: 300.0

  111. 307

    200

    124

    453

    Returns: 1812.0

  112. 100

    1000

    10

    47

    Returns: 846.0

  113. 100

    100

    50

    123

    Returns: 246.0

  114. 101

    11

    20

    47

    Returns: 470.0

  115. 100

    100

    50

    50

    Returns: 100.0

  116. 10

    100

    9

    3

    Returns: 6.0

  117. 2

    50

    1

    1

    Returns: 2.0

  118. 100

    11

    20

    47

    Returns: 376.0

  119. 6

    30

    1

    1

    Returns: 10.0

  120. 2

    3

    1

    1

    Returns: 2.0

  121. 5

    3

    2

    47

    Returns: 141.0

  122. 10

    9

    2

    1

    Returns: 8.0

  123. 100

    4

    74

    47

    Returns: 94.0

  124. 19

    100

    9

    3

    Returns: 12.0

  125. 100

    10

    20

    47

    Returns: 376.0

  126. 901

    1000

    100

    1

    Returns: 18.0

  127. 41

    11

    20

    47

    Returns: 188.0

  128. 5

    4

    2

    5

    Returns: 20.0

  129. 1

    3

    1

    13

    Returns: 13.0

  130. 100

    20

    20

    47

    Returns: 376.0

  131. 850

    10

    170

    849

    Returns: 6792.0

  132. 20

    100

    2

    2

    Returns: 36.0

  133. 1000

    1000

    999

    47

    Returns: 94.0

  134. 30

    100

    10

    1000

    Returns: 4000.0

  135. 100

    100

    27

    47

    Returns: 282.0

  136. 20

    3

    10

    10

    Returns: 20.0

  137. 1000

    80

    200

    51

    Returns: 408.0

  138. 100

    3

    50

    47

    Returns: 94.0

  139. 102

    5

    50

    40

    Returns: 160.0

  140. 100

    100

    50

    47

    Returns: 94.0


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: