cswork / OA打开练习工作台

AmazonOA #225

Get Minimal Cost

估计困难可在线判题

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

Each product's size can only increase, and each unit of increase costs that product's cost. In the end all product sizes must be distinct; find the minimum total cost. Products cannot be removed.

输入格式

The first line contains n, the second line the sizes, and the third line the unit costs. 1≤n≤200000, 1≤size≤10^9, 1≤cost≤10000.

输出格式

Output a single integer, the answer.

样例 1

输入:

5
3 7 9 7 8
5 2 5 7 5

输出:

6

样例 2

输入:

4
2 3 3 2
2 4 5 1

输出:

7

样例 3

输入:

2
1 1
1 10

输出:

1

样例说明

The answers are 6, 7 and 1. In the second example the 3 with cost 4 rises to 4 and the 2 with cost 1 rises to 5, total 7.