AmazonOA #39
Get Minimal Cost (Distinct Sizes)
估计困难可在线判题
Each increase of 1 to the i-th size costs cost[i]; sizes can only increase, never decrease. Make all sizes pairwise distinct and find the minimum total cost.
输入格式
The first line contains n (1..200000), the second line contains n size values (1..10⁹), and the third line contains n cost values (1..10000).
输出格式
Output a single integer answer.
样例 1
输入:
4
2 3 3 2
2 4 5 1
输出:
7
样例 2
输入:
2
1 1
1 9
输出:
1
样例 3
输入:
2
1 4
9 9
输出:
0
样例说明
Example 1: the size-2 item with cost 2 stays at 2, the size-3 item with cost 5 stays at 3, the other 3 with cost 4 increases to 4 for 4, and the other 2 with cost 1 increases to 5 for 3, for a total cost of 7. Example 2: the expensive item stays at 1 and the cheap item increases by 1, for a cost of 1. Example 3: the sizes are already distinct, so the cost is 0.