Official algorithmic problem description and constraints.
Gorilla and Noobish_Monk found three numbers π, π, and π (π<π). They decided to construct a permutationβ of length π.
For the permutation, Noobish_Monk came up with the following function: π(π) is the sum of all the numbers in the permutation on a prefix of length π that are not greater than π. Similarly, Gorilla came up with the function π, where π(π) is the sum of all the numbers in the permutation on a prefix of length π that are not less than π. A prefix of length π is a subarray consisting of the first π elements of the original array.
For example, if π=5, π=2, π=5, and the permutation is [5,3,4,1,2], then:
Help them find a permutation for which the value of (βπ=1ππ(π)ββπ=1ππ(π)) is maximized.
Detailed video explanations, mathematical intuition, and clean C++ implementation code.