#P10695. Non‐Intersecting Antipodal Business Routes
Non‐Intersecting Antipodal Business Routes
Non‐Intersecting Antipodal Business Routes
Consider a circle on which equally–spaced points are marked with clockwise labels . Among these points, markets are constructed at positions (given as a sorted list of point labels). For each market (with angle $$\theta_i=2\pi\frac{a_i-1}{K}$$), we define its valid business route(s) as a directed segment from to some other market such that:
- The target market is one of the farthest markets from , that is, $$M_j;\text{maximizes}; d(M_i,M_k);\text{for }k\neq i,$$ where the distance is measured by the chord length. (Equivalently, if we define
then is chosen so that $$d(M_i,M_j)=\max_{k\neq i} d(M_i,M_k).$$ In the case of a tie (which may happen, for example, when the markets form a regular polygon) any of the farthest markets may be chosen.
- No two chosen business routes (drawn as the straight line segments connecting the corresponding markets) are allowed to intersect or coincide at any interior point (they may meet at endpoints).
Your task is to select a subset of the valid business routes so that the number of routes is maximized and the non–intersection constraint is satisfied. Note that if two valid routes share an endpoint, that is allowed.
For example, if the markets are placed so that they form a square (with and the farthest from each market is unique – namely the diametrically opposite market), the only valid routes (as undirected segments) are the two diameters; however, since any two different diameters intersect at the center, at most one business route can be chosen. In contrast, when the markets form an equilateral triangle () every market has two farthest choices (in fact every edge is valid) and all three edges may be chosen (since the edges meet only at vertices).
It can be shown that, given the positions of the markets, the valid routes (if we remove duplicate oppositely–directed edges) form a set of chords on a circle. Two chords from conflict (i.e. they intersect in a point other than an endpoint) if and only if they do not share an endpoint and their endpoints are interlaced in the circle – more precisely, if after identifying each chord with the unordered pair (with angles normalized so that the chord always represents the shorter arc, expressed in (\LaTeX) as
$$\{\theta_a,\theta_b\}\n\quad\text{with} \quad \theta_a<\theta_b\quad \text{and} \quad \theta_b-\theta_a\le \pi), $$then two chords and (with normalized endpoints and , and assuming ) intersect if and only if $$\theta_a<\theta_c<\theta_b<\theta_d.$$
Your job is to compute the maximum number of business routes that can be chosen from the candidate set so that no two non–adjacent chords intersect.
Input and output formats are described below.
inputFormat
The first line contains two integers and (). The second line contains distinct integers in increasing order (each between and ) indicating the positions (labels) where the markets are built.
outputFormat
Output a single integer – the maximum number of business routes (i.e. non–intersecting chords chosen among the candidate valid routes) that can be selected.
sample
4 4
1 2 3 4
1