Optimal Constructives

10/20


Warm-Up

You are given an array of 2𝑛 integers. You want to put them into pairs (π‘₯1,𝑦1),(π‘₯2,𝑦2)…(π‘₯𝑛,𝑦𝑛) such that each integer is in exactly one pair. Your score is defined as the sum of |π‘¦π‘–βˆ’π‘₯𝑖| over all pairs. What’s the maximum score you can achieve?

Example: π‘Ž=[1,3,2,4]β‡’(1,3),(2,4)


Optimal Constructives

Construct ___ such that ___ is maximized/minimized.


Adjacent Delete


Solution

(for now, assume 𝑛 is even) Ideally, we always pair the largest 𝑛2 elements with the smallest 𝑛2 elements. The cool thing is it turns out that this is always possible!

We can use a simple inductive proof. When 𝑛=0, it is obviously always possible. Then, when 𝑛>0, note that there must always be a β€œlarge” element adjacent to a β€œsmall” element. Therefore, we can simply delete this pair, and recurse to π‘›βˆ’2.

𝑛 odd case is left as an exercise to the reader/viewer.


Manhattan Pairs


Solution

The idea is similar to that of Adjacent Delete. Let’s shift our coordinate axes such that exactly half the points are above the π‘₯-axis, and exactly half the points are to the right of the 𝑦-axis. Then, our goal is to pair points in the first quadrant with points in the third quadrant, and points in the second quadrant with points in the fourth quadrant.

Again, it turns out that this is always possible!


Bounds

The next two problems involve finding good upper/lower bounds on the answer that will decrease our search space significantly.


Mr Kitayuta’s Technology




Solution

First observe that we can solve each weakly connected component separately.

Now, notice that in a component of 𝑛 nodes, we can always satisfy all relations by using only 𝑛 edges, simply by connecting the entire component in a cycle. We also definitely can’t use less than π‘›βˆ’1 edges, otherwise the component won’t be connected anymore. Therefore, the question becomes: can we satisfy all required relations in this component using only π‘›βˆ’1 edges (sound familiar?)


Maple and Tree Beauty


Solution

Let 𝑑 be the minimum depth of any node. Then, it turns out the answer is always at least π‘‘βˆ’1 (how?) Therefore, we just need to know whether we can achieve an answer of exactly 𝑑 or not, which can be done via a subset sum DP.