#P10695. Non‐Intersecting Antipodal Business Routes

    ID: 12725 Type: Default 1000ms 256MiB

Non‐Intersecting Antipodal Business Routes

Non‐Intersecting Antipodal Business Routes

Consider a circle on which KK equally–spaced points are marked with clockwise labels 1,2,,K1,2,\dots,K. Among these points, markets M1,M2,,MnM_1,M_2,\dots,M_n are constructed at positions a1,a2,,ana_1,a_2,\dots,a_n (given as a sorted list of point labels). For each market MiM_i (with angle $$\theta_i=2\pi\frac{a_i-1}{K}$$), we define its valid business route(s) as a directed segment from MiM_i to some other market Mj (ij)M_j\ (i\neq j) such that:

  1. The target market MjM_j is one of the farthest markets from MiM_i, 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
$$d(M_i,M_k)=2R\;\sin\Bigl(\frac{\min(|\theta_i-\theta_k|,2\pi-|\theta_i-\theta_k|)}{2}\Bigr), $$

then MjM_j 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.

  1. 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 n=4n=4 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 (n=3n=3) 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 EE of chords on a circle. Two chords from EE 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 (Mi,Mj)(M_i,M_j) with the unordered pair {i,j}\{i,j\} (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 (Mi,Mj)(M_i,M_j) and (Mk,Ml)(M_k,M_l) (with normalized endpoints θa,θb\theta_a,\theta_b and θc,θd\theta_c,\theta_d, and assuming θa<θc\theta_a<\theta_c) 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 EE so that no two non–adjacent chords intersect.

Input and output formats are described below.

inputFormat

The first line contains two integers KK and nn (nKn\le K). The second line contains nn distinct integers a1,a2,,ana_1,a_2,\dots,a_n in increasing order (each between 11 and KK) 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