Problem J
Galaxy Quest
NASA recently confirmed the discovery of parallel universes (PUs) occupying alternate dimensions. These universes are quite different from our own universe, in the following ways:
-
Each PU is a two-dimensional square that stretches
light years from left to right and from top to bottom. -
Each PU has a galactic diameter of
light years, where is an integer. -
Each star is exactly
light years from its universe’s left edge and light years from its universe’s bottom edge, where and are non-negative integers. -
Stars are clustered into galaxies. Each galaxy consists of one or more stars. Each star is at most
light years from every other star in its galaxy. Any two stars from different galaxies are more than light years apart.It is crucial to understand the implications of this. The locations of the stars determine the galaxies. The galaxy to which a star
belongs consists of plus all other stars that are within light years of . Suppose you draw a circle of diameter around all of the stars of a galaxy. Any star not belonging to the galaxy will be outside the circle and will be more than light years from every star in the galaxy.
For each PU, NASA has obtained all of its stellar
coordinates and has measured its value of
Given the description of a PU, NASA would like to be able to determine whether that PU has a galaxy that contains more than half of the stars in the PU. NASA has turned to you.
Input
The input describes a single PU. All numbers in the input are integers.
The first line of the input contains the PU’s galactic
diameter
There are exactly
The star positions and
Output
If the PU described by the input has a galaxy containing more than half of the stars, display the number of stars in that galaxy. Otherwise, display NO.
Sample Input 1 | Sample Output 1 |
---|---|
10 4 45 46 90 47 45 54 90 43 |
NO |
Sample Input 2 | Sample Output 2 |
---|---|
20 7 1 1 100 100 1 3 101 101 3 1 102 102 3 3 |
4 |