ICPC Asia Pacific Championship 2026 — Solution K. Time Display Stickers

K  Time Display Stickers

We can separate time displays into two different types:

  1. time displays whose hour is between \(00\) and \(09\) (let’s say these are time displays of type A), and
  2. time displays whose hour is between \(10\) and \(11\) (let’s say these are time displays of type B).

We want to check whether it is possible to create \(x\) time displays of type A and \(y\) time displays of type B. We can do this by greedily assigning stickers to positions with the fewest possible stickers to be put into first.

In other words, we can do the following steps:

Possible stickers
HHMM
Type A\(0\)\([0, 9]\)\([0, 5]\)\([0, 9]\)
Type B\(1\)\([0, 1]\)\([0, 5]\)\([0, 9]\)
  1. Assign \(x\) stickers numbered \(0\) to the first H position for \(x\) time displays of type A.
  2. Assign \(y\) stickers numbered \(1\) to the first H position for \(y\) time displays of type B.
  3. Combine the remaining stickers numbered \(0\) and \(1\) together, and assign \(y\) of them to the second H position for \(y\) time displays of type B.
  4. Combine the remaining stickers numbered \(0\) to \(5\) together, and assign \(x+y\) of them to the first M position for \(x + y\) time displays.
  5. Combine the remaining stickers numbered \(0\) to \(9\) together, and assign \(2x + y\) of them to the remaining positions.

If, at any step, we don’t have enough number of required stickers, then it is not possible to create \(x\) time displays of type A and \(y\) time displays of type B.

To find the maximum value of \(x + y\) among all valid values of \(x\) and \(y\), we can try all possible values of \(x\) from \(0\) to \(n\) and use binary search to find the maximum valid value of \(y\) for the corresponding value of \(x\).

This solution solves the problem in \(O(n \log n)\).