cswork / OAOpen practice workspace

AmazonOA #64

Get Optimal Sequence

Estimated MediumStatement and editorial — judging is being prepared

Topics (AI-labelled)Stacks & HeapsGreedySimulation

Given values[n], binary state (length n), and integer m. In each operation, pick an index where state[i] = '1', append values[i] to S, then for every "blocked-then-unblocked" rule, change one specific '0' to '1'. Maximize the lexicographic order of S of length m.

Constraints

  • 1 ≤ n, m ≤ 10⁵
  • 1 ≤ values[i] ≤ 10⁹

Editorial

Loading solution…