Official algorithmic problem description and constraints.
Dmitry has π cubes, numbered from left to right from 1 to π. The cube with index π is his favorite.
Dmitry threw all the cubes on the table, and the π-th cube showed the value ππ (1β€ππβ€100). After that, he arranged the cubes in non-increasing order of their values, from largest to smallest. If two cubes show the same value, they can go in any order.
After sorting, Dmitry removed the first π cubes. Then he became interested in whether he removed his favorite cube (note that its position could have changed after sorting).
For example, if π=5, π=2, π=[4,3,3,2,3] (the favorite cube is highlighted in green), and π=2, the following could have happened:
Detailed video explanations, mathematical intuition, and clean C++ implementation code.