MicrosoftOA #63
Skyscraper
估计简单可在线判题
考点(AI 标注)贪心调度
Assign each building a positive integer height B[i] not exceeding its limit A[i], such that all heights are distinct and their sum is maximized. A solution is guaranteed to exist, and any optimal assignment is accepted.
This site uses a standard input/output protocol.
输入格式
The first line contains N (1..50000), and the second line contains N values A[i] (1..10⁹); a valid assignment of distinct positive integers is guaranteed to exist.
输出格式
Output N positive integer heights B, keeping the buildings in their original input order.
样例 1
输入:
3
1 2 3
输出:
1 2 3
样例 2
输入:
5
9 4 3 7 7
输出:
9 4 3 6 7
样例 3
输入:
5
2 5 4 5 5
输出:
1 2 3 4 5
样例说明
Example 1: every building can take its limit, for a total of 6. Example 2: the two limits of 7 become 7 and 6, and the others are 9, 4, 3, for a total of 29; the assignments of the two buildings with limit 7 can be swapped. Example 3: only the five distinct heights 1..5 are available, for a total of 15; for example, 1, 2, 3, 4, 5 is valid.