Statistics

Problem Statement for "ThreeWatchtowers"

Problem Statement

You wish to build three watchtowers to overlook several points of interest. The points of interest are given in the int[]s x and y, where each element of x and the corresponding element of y represent the coordinates of a single point of interest.

Each of the three watchtowers has a field of view that is the same in all directions. The viewing distance of each of the three watchtowers is given in the int[] view, so the i-th watchtower can see all points which are located not further than view[i] units from it. Assuming optimal placement, return the maximum number of points of interest that are within view of at least one of the watchtowers.

Definition

Class:
ThreeWatchtowers
Method:
maximumCoverage
Parameters:
int[], int[], int[]
Returns:
int
Method signature:
int maximumCoverage(int[] x, int[] y, int[] view)
(be sure your method is public)

Notes

  • Even though points of interest are restricted to a given area, the watchtowers themselves may be located outside of that area, and do not necessarily have to be placed on lattice points.
  • A watchtower can see a point exactly on the edge of its field of view. Thus, a watchtower at (0, 0) with a radius of 2 could see a point at (0, 2).

Constraints

  • x and y will each contain between 1 and 20 elements, inclusive.
  • x and y will each contain the same number of elements.
  • Each element of x and y will be between 0 and 20, inclusive.
  • view will contain exactly 3 elements.
  • Each element of view will be between 1 and 20, inclusive.

Examples

  1. {5, 10, 5, 20, 4, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 2, 3, 4, 6, 7}

    {5, 10, 5, 5, 6, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 1, 2, 3, 3, 2}

    {20, 20, 20}

    Returns: 20

  2. {0, 10, 20}

    {15, 16, 20}

    {1, 1, 1}

    Returns: 3

    Even though the watchtowers can't see very far, with only three points of interest, it is trivial to cover them all.

  3. {0, 1, 10, 20, 15, 14}

    {1, 0, 10, 20, 18, 12}

    {2, 2, 2}

    Returns: 4

    The first two points are close enough together to be covered by a single watchtower. The other points are too spread out, so the other two towers can each only see a single point.

  4. {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}

    {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}

    {1, 1, 13}

    Returns: 10

    The first two watchtowers are not really needed, since the last one has a wide enough range to see all 10 points at once.

  5. {0, 5, 6, 16, 18, 20}

    {0, 6, 7, 20, 20, 20}

    {1, 3, 5}

    Returns: 6

    The first watchtower covers the first point. The second watchtower can cover the next two points. The last three points can be covered by the final tower.

  6. {0, 0, 1, 1, 2, 0}

    {10, 20, 2, 0, 1, 1}

    {1, 1, 1}

    Returns: 6

  7. {0, 0, 0, 0}

    {0, 10, 18, 20}

    {1, 1, 1}

    Returns: 4

  8. {0, 0, 1, 1, 2, 0}

    {10, 20, 2, 0, 1, 1}

    {1, 1, 2}

    Returns: 6

  9. {0,20,1,20,20}

    {10,10,0,1,10}

    {10,1,1}

    Returns: 5

  10. {0, 0, 6, 0, 20}

    {0, 8, 0, 20, 0}

    {1, 1, 5}

    Returns: 5

  11. {11,1,19,20,0}

    {10,1,1,20,20}

    {19,1,1}

    Returns: 5

  12. {10,19,18,0,20}

    {10,20,10,0,0}

    {19,1,1}

    Returns: 5

  13. {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19}

    {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19}

    {20, 20, 20}

    Returns: 20

  14. {1,0}

    {0,0}

    {1,1,1}

    Returns: 2

  15. {1, 2, 0, 3, 1}

    {0, 3, 2, 1, 0}

    {1, 1, 1}

    Returns: 4

  16. {4,13,0,15,13}

    {6,13,16,7,12}

    {3,2,2}

    Returns: 4

  17. {1,4,7,5,4}

    {7,5,2,7,1}

    {1,2,1}

    Returns: 4

  18. {18,4,5,14}

    {12,11,7,13}

    {12,14,18}

    Returns: 4

  19. {17,15,11,3,20,18,10,10}

    {17,15,13,18,7,12,2,12}

    {15,18,7}

    Returns: 8

  20. {16,3,6,16,13}

    {3,18,13,12,0}

    {8,7,7}

    Returns: 5

  21. {20,18,1,20,4,2,10,4,17,11,13,19,14,3,14,7,20,15,15}

    {7,0,3,5,10,12,6,0,12,9,19,5,20,1,14,0,12,13,19}

    {18,19,10}

    Returns: 19

  22. {12,7}

    {5,15}

    {15,16,4}

    Returns: 2

  23. {9}

    {7}

    {9,14,13}

    Returns: 1

  24. {1,0,11,0,1,0,20,0,9,1,14,8,16,17}

    {2,1,3,17,2,10,20,6,3,5,7,11,15,18}

    {11,5,3}

    Returns: 14

  25. {16,4,19,0,7,10,14,5,11,7,17,1,14,15,13,16,7}

    {5,18,0,16,14,5,0,1,14,8,11,9,15,20,2,7,4}

    {2,5,5}

    Returns: 12

  26. {15,16,0,19,4,3}

    {7,12,13,5,12,15}

    {16,12,16}

    Returns: 6

  27. {6,2,17,17,5,0,2,2,9,15,4,10,13,5,17,6,7,16}

    {5,6,13,9,17,5,9,12,9,13,10,16,20,15,12,16,5,9}

    {20,1,13}

    Returns: 18

  28. {18,17,19,9,9,17}

    {2,9,18,8,19,16}

    {19,11,3}

    Returns: 6

  29. {6,19,8,9,17,7,7,3,8,3,16,19,8}

    {2,0,1,10,11,0,10,5,12,3,13,11,17}

    {10,17,16}

    Returns: 13

  30. {6,13}

    {10,10}

    {1,12,12}

    Returns: 2

  31. {0,1,20,8,20,13,7,0,5,10,13,0,1,20,19,3,19,15,13}

    {3,9,17,20,15,8,4,7,9,18,7,11,3,20,7,14,13,7,0}

    {12,7,10}

    Returns: 19

  32. {11,8,11,8,3,4,11,15,9}

    {12,7,4,7,3,9,4,2,18}

    {9,5,11}

    Returns: 9

  33. {5,19,14,1,9,10,17,16,12,15,9,19,0,1}

    {15,7,20,8,6,6,16,7,14,0,8,11,1,20}

    {5,12,5}

    Returns: 14

  34. {18,15,8,17}

    {17,8,18,20}

    {15,8,16}

    Returns: 4

  35. {0,9,10,7,5,16,8,8,5,13,14,20,8,3}

    {10,18,16,17,9,6,18,13,20,1,0,4,12,11}

    {17,4,14}

    Returns: 14

  36. {1,20,4,16,10,15,1,2,5,11,5,13,9,19,14,16,13}

    {8,0,15,5,12,16,20,10,6,14,4,20,2,9,10,14,20}

    {13,7,13}

    Returns: 17

  37. {11,10,7}

    {9,1,14}

    {11,16,19}

    Returns: 3

  38. {8,14,15,1,2,9,1,13,17,1,19,13,5,1,9,19,8}

    {18,10,13,14,18,3,15,1,14,20,17,14,12,10,3,10,2}

    {6,1,9}

    Returns: 17

  39. {2,6,11}

    {20,3,8}

    {12,20,18}

    Returns: 3

  40. {16,2,14,7}

    {15,19,4,1}

    {19,16,15}

    Returns: 4

  41. {20,6,13,19,10,0,10,3,5,10,4,1,4,7}

    {2,4,1,15,1,10,6,2,19,3,17,3,19,11}

    {10,2,2}

    Returns: 13

  42. {8,16,14,6,20,18,4,5,13,11,13,1,5,13,12,15,15,4}

    {5,20,11,4,20,14,20,10,13,8,5,20,18,2,1,20,18,9}

    {9,3,3}

    Returns: 18

  43. {11,3,13,11,7,5,8,12,12,6,16,17,1,18,14,13,4,17,12}

    {15,15,18,17,0,18,16,10,10,6,1,0,16,1,4,11,11,19,12}

    {5,10,14}

    Returns: 19

  44. {18}

    {2}

    {7,10,16}

    Returns: 1

  45. {11,2,0,15,11,5,16,5,20,1,18,13}

    {6,3,15,10,5,13,13,6,11,0,20,20}

    {2,4,17}

    Returns: 12

  46. {17,9,1}

    {5,1,3}

    {7,12,3}

    Returns: 3

  47. {10,9,7,16,5,20,17,17,0}

    {16,1,6,4,20,14,0,6,17}

    {14,14,19}

    Returns: 9

  48. {8,0,5,16,0,13,2,11,14,6,5,15,3,13,1,15,18,4,19,5}

    {9,7,0,11,4,13,5,13,13,13,9,6,11,8,1,9,5,2,9,6}

    {1,1,1}

    Returns: 4

  49. {7,2,20,6,1,1,13,11,3,4,19,4,17,5,19,9,18,13,16,5}

    {8,9,11,11,8,4,19,17,2,14,17,5,9,6,7,12,14,7,18,7}

    {1,1,1}

    Returns: 5

  50. {2,14,15,17,2,6,20,14,8,15,11,8,5,13,19,12,15,13,1,1}

    {13,0,3,7,8,8,20,7,0,14,2,1,12,13,18,12,5,19,11,14}

    {1,1,2}

    Returns: 7

  51. {7,8,13,8,15,7,6,0,1,12,16,20,20,20,16,14,16,16,3,11}

    {15,2,14,11,7,9,17,15,11,3,11,1,9,1,9,20,17,10,10,1}

    {1,1,1}

    Returns: 6

  52. {4,12,20,9,7,4,9,15,14,8,14,4,12,13,0,18,16,16,9,10}

    {14,1,20,7,7,5,0,1,1,13,19,4,2,8,20,9,15,14,20,10}

    {2,1,1}

    Returns: 8

  53. {4,13,13,5,0,1,18,16,20,17,17,1,14,4,19,7,20,18,12,4}

    {18,17,2,1,15,4,20,4,5,15,10,14,5,0,14,6,16,1,10,14}

    {4,1,1}

    Returns: 9

  54. {2,8,5,11,14,10,19,15,20,17,14,8,2,15,10,16,11,13,20,2}

    {6,17,0,17,1,4,5,7,15,14,1,3,20,19,3,20,17,5,1,8}

    {4,1,1}

    Returns: 10

  55. {10,19,10,9,2,8,14,0,1,8,5,13,3,10,8,16,3,15,1,13}

    {10,6,19,19,18,19,15,20,7,1,10,19,10,15,12,16,3,1,4,16}

    {1,4,2}

    Returns: 11

  56. {15,8,16,7,10,1,15,11,12,13,18,16,6,14,18,17,8,17,16,1}

    {14,5,12,4,18,15,20,4,5,10,13,12,18,10,16,11,10,16,6,1}

    {4,1,1}

    Returns: 13

  57. {11,8,0,8,17,10,5,1,8,14,5,16,18,6,13,12,15,8,9,14}

    {15,13,7,12,2,6,7,3,3,20,12,1,4,3,20,13,0,3,0,13}

    {1,3,4}

    Returns: 12

  58. {6,16,19,7,18,8,16,15,4,3,20,0,12,5,13,19,18,8,3,9}

    {18,5,9,1,20,2,6,5,16,11,2,17,6,10,14,7,9,4,0,9}

    {1,8,1}

    Returns: 15

  59. {10,15,11,15,6,14,0,13,4,14,10,8,0,20,9,3,3,7,19,6}

    {10,13,17,13,1,10,9,0,13,17,14,4,13,7,19,17,18,12,7,11}

    {5,3,1}

    Returns: 14

  60. {9,12,10,20,18,14,12,8,20,7,4,6,4,20,9,2,8,7,14,12}

    {7,11,7,19,18,8,14,8,18,8,0,17,12,1,12,14,4,6,0,15}

    {6,2,1}

    Returns: 16

  61. {20,9,12,2,3,20,0,1,4,18,12,16,8,0,10,10,10,11,12,15}

    {20,15,15,15,13,0,2,8,6,9,0,7,9,12,17,5,13,16,17,3}

    {1,9,1}

    Returns: 17

  62. {17,2,13,11,0,7,0,10,6,9,0,20,17,11,7,2,14,9,10,1}

    {13,9,5,2,6,0,17,2,2,2,3,2,14,2,6,7,18,14,19,1}

    {3,1,8}

    Returns: 18

  63. {14,13,9,18,0,13,0,1,5,1,10,15,18,2,17,9,16,1,14,1}

    {12,13,15,15,10,20,11,10,18,13,11,16,9,3,17,1,19,19,19,13}

    {1,1,10}

    Returns: 20

  64. {1,20,13,11,3,19,20,8,15,6,14,15,8,2,5,4,8,1,5,19}

    {0,0,7,14,17,3,19,3,16,18,8,12,1,8,12,7,9,12,7,11}

    {6,7,5}

    Returns: 19

  65. {10, 18, 16, 9, 17, 20, 4, 3, 11, 9}

    {4, 17, 6, 14, 14, 14, 12, 12, 13, 16}

    {1, 1, 2}

    Returns: 7

  66. {0,9,7,20,20}

    {0,3,7,0,20}

    {5,1,1}

    Returns: 5

  67. {0,9,4,20,20}

    {0,3,8,0,20}

    {5,1,1}

    Returns: 5

  68. {0,8,4,20,20}

    {0,0,8,0,20}

    {5,1,1}

    Returns: 5

  69. {0,6,3,20,20}

    {0,0,9,0,20}

    {5,1,1}

    Returns: 5

  70. {0, 1, 10, 20, 15, 14 }

    {1, 0, 10, 20, 18, 12 }

    {2, 2, 2 }

    Returns: 4

  71. {0, 10, 20 }

    {15, 16, 20 }

    {1, 1, 1 }

    Returns: 3

  72. {1, 2, 0, 3, 1 }

    {0, 3, 2, 1, 0 }

    {1, 1, 1 }

    Returns: 4

  73. {10, 18, 16, 9, 17, 20, 4, 3, 11, 9 }

    {4, 17, 6, 14, 14, 14, 12, 12, 13, 16 }

    {1, 1, 2 }

    Returns: 7

  74. {1, 3, 5, 7, 9 }

    {2, 2, 2, 2, 2 }

    {1, 1, 1 }

    Returns: 5

  75. {0, 1, 3, 4, 5, 7, 8, 9, 11 }

    {0, 3, 0, 8, 11, 8, 1, 4, 1 }

    {2, 2, 2 }

    Returns: 9

  76. {2, 5, 4, 9, 12, 10, 3, 8, 4, 6, 3, 4, 12, 19, 20, 18, 15, 13, 16, 1 }

    {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 }

    {2, 3, 3 }

    Returns: 13


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: