A histogram represents a data distribution. Here a histogram of width W is given by an even-length sequence of points
(x0,y1),(x1,y1),(x1,y2),(x2,y2),…,(xN/2−1,yN/2),(xN/2,yN/2)
in the plane. Each adjacent pair shares an x or a y coordinate, and horizontal and vertical segments alternate.
The shape must satisfy:
For histogram H, let yH(x) be the height on unit interval ⟨x,x+1⟩. Two error measures are used:
diffcount(H′,H)=∑x=0W−1diff(yH(x),yH′(x)),diff(y1,y2)=0 if y1=y2 else 1
abserror(H′,H)=∑x=0W−1∣yH(x)−yH′(x)∣
Given H, a point set S, and the measure G, find a histogram H′ that uses only points from S and minimizes the chosen error.
Line 1: integers N,M,G (2≤N≤100000, N even, 2≤M≤100000, 1≤G≤2). G=1 selects diffcount, G=2 selects abserror.
Next N lines: points (X,Y) defining histogram H.
Next M lines: points (X,Y) in set S. (0≤X≤106, 1≤Y≤106)
Line 1: minimum error D.
Line 2: even integer L, the number of points in the optimal histogram.
Next L lines: coordinates X Y of those points. The definition must satisfy every rule from the statement.