Codeforces
CF Step
Youtube Linkedin Discord Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage

Hints: Course Wishes

You only ever increase a course’s wish level by $1$. So each course must be moved along $k{+}1 - b_i$ steps from its starting level $b_i$ to level $k{+}1$. The only question is in what order to touch courses so that every intermediate state respects the caps $a_1,\ldots,a_k$.

Answer to Hint 1: If a course is already at a higher wish level (closer to $k{+}1$), moving it further is usually “safer” for the tight upper levels, because it pulls mass toward the unlimited level $k{+}1$ first.

Try sorting courses by decreasing current level $b_i$ before simulating the increases.

Answer to Hint 2: After that sort, walk the courses in order. For each course, while its level is still at most $k$, append one operation on that course and increment its level.

You never need more than $n \cdot k \le 1000$ operations under the limits, and this greedy order keeps capacities valid whenever a solution exists.

Answer to Hint 3: Implementation detail: store pairs $(b_i, i)$, sort descending by $b_i$, then expand each course’s ID into the output list the required number of times. Print the list size and the sequence.