Official

F - Make Same Set Editorial by evima

A big hint

Consider relaxing the first and second conditions into the following.

  • It can be obtained as follows: start with an empty set, and for each \(i=1,2,\dots,N\) in this order, add \(A_i\), \(B_i\), or nothing to the set.
  • It can be obtained as follows: start with an empty set, and for each \(i=1,2,\dots,N\) in this order, add \(A_i\), \(C_i\), or nothing to the set.

The maximum number of elements in a set satisfying these conditions is clearly an upperbound for the original problem.

Actually, this upperbound is achievable.

posted:
last update: