Observation
I don't understand your solution.
Code Review
#define max(a, b) (a > b ? a : b) // std::max(a, b)
#define max(a, b) (a > b ? a : b) // std::max(a, b)
Don't do this. Use std::max() directly.
Long gone are the days that we used macros to inline code like this. The std::max() will work correctly in all situationsituations; this macro has edge casedcases that will fail (especially if a or ba and b are not just simple numbers).
The size_tsize_t is coming because you included a C header file cstdint. It is not guaranteed to be in the global namespace (it commonly is but its not guaranteed). So prefer to use std::size_t.
const std::size_t max_nums = *std::max_element(nums.begin(), nums.end());