cswork / OA打开练习工作台

AmazonOA #388

Minimal Cost to Increase Package Size

估计困难可在线判题

考点(AI 标注)单调栈与堆贪心调度

Item i has initial size size[i]; each increase by 1 costs cost[i], and sizes cannot decrease. Make all final sizes pairwise distinct and find the minimum total cost.

输入格式

The first line contains n, the second line contains n sizes, and the third line contains n unit costs. OCR141/142/143 and the supplementary text of the same problem restore the complete original bounds: 1≤n≤200000, 1≤size[i]≤10^9, 1≤cost[i]≤10000.

输出格式

Output a single integer answer.

样例 1

输入:

4
2 3 2 2
2 4 5 1

输出:

7

样例 2

输入:

2
1 1
1 9

输出:

1

样例 3

输入:

2
1 100
3 2

输出:

0

样例说明

The minimum for the first example is 7: the item with cost 5 stays at 2, the item with cost 4 stays at 3, the item with cost 2 goes from 2 to 4 for 4, and the item with cost 1 goes from 2 to 5 for 3. The "1+4=7" explanation in the original supplementary text contains an arithmetic error; this site uses the correct process. The answers to the other two examples are 1 and 0.