The Data Pair\(\textit{people}[h, k]\), \(h_i\) represents the i-th person of height \(h_i\), \(k_i\) represents the other people in front who have a height greater than or equal to \(h_i\).
Pattern:
When face such kind of problem with Data Pair, sorting first will simplify the problem.
Usually, we will sort the first element in ascending order, while the second element in descending order, or sort the first element in descending order with the second element in ascending order.
Greedy
We sort the \(\textit{people}\) pairs first by \(height\) in descending order, and \(k\) in ascending order.
According to the descending order of \(height\), for each person, the number of people before him is the number of people whose height is greater than or equal to him.
According to the ascending order of \(k\), because the \(k\) is increase later, which can reduce the number of insert operations.
While we are moving, we will need to use bricks or ladders several times. Suppose we have to move to the next building, which means we must use one ladder or \(\Delta h\) bricks, so there is a question, whether to use ladders or bricks?
If the gap of buildings is large, we may use the ladder, otherwise we use the bricks.
We can consider ladder as a one-time unlimited number of bricks, That is, if we have l ladders, we will use the ladder on the \(l\) times where \(\Delta h\) is the largest, and use the bricks in the rest.
Therefore, we got the answer. We maintain no more than \(l\) largest \(\Delta h\) using priority queues, and these are where the ladders are used. For the remaining \(\Delta h\), we need to use bricks, so we need to accumulate them, if the \(sum\) exceeds the number of bricks \(b\), then we have move to the furthest building.