Official algorithmic problem description and constraints.
Alice, Bob and Charlie want to share a rectangular cake cut into π pieces. Each person considers every piece to be worth a different value. The π-th piece is considered to be of value ππ by Alice, ππ by Bob and ππ by Charlie.
The sum over all ππ, all ππ and allππ individually is the same, equal to π‘ππ‘.
Given the values of each piece of the cake for each person, you need to give each person a contiguous slice of cake. In other words, the indices at the left and right ends of these subarrays (the slices given to each person) can be represented as (ππ,ππ), (ππ,ππ) and (ππ,ππ) respectively for Alice, Bob and Charlie. The division needs to satisfy the following constraints:
Here, the notation βππβ represents ceiling division. It is defined as the smallest integer greater than or equal to the exact division of π by π. In other words, it rounds up the division result to the nearest integer. For instanceβ103β=4 and β153β=5.
Detailed video explanations, mathematical intuition, and clean C++ implementation code.