P6155 Modification.
Description
Given an integer sequence $a_i$ of length $n$, and an integer sequence $b_i$ of length $n$.
You can do some modifications. Each time, you may increase one $a_i$ by $1$, and the cost is $b_i$. You need to make all $a_i$ pairwise distinct, and at the same time minimize the total cost.
However, zbw thinks this is too easy, so he specifies that before making modifications, you may perform the following operation **an unlimited** number of times: swap $b_i$ and $b_j$ $(1 \leq i,j \leq n)$.
Find the minimum cost.
**Since the answer may be very large, output the value modulo $2^{64}$.**
Input Format
The first line contains an integer $n$.
The second line contains $n$ integers; the $i$-th number denotes $a_i$.
The third line contains $n$ integers; the $i$-th number denotes $b_i$.
Output Format
Output one integer in one line, which is the answer modulo $2^{64}$.
Explanation/Hint
Sample $1$: do not change $b$. Increase $a_1$ by $2$ and $a_2$ by $1$, and the total cost is $4$.
Sample $2$: swap $b_1$ and $b_3$. Increase $a_1$ by $2$, and the total cost is $2$.
Sample $3$: do not change anything.
**The input size of this problem is large, so please use fast input.**
| Test Point | $n$ | $a_i$ | Special Property |
| :----------: | :----------: | :----------: | :----------: |
| $1,2$ | $\leq 10$ | $\leq 10^9$ | None |
| $3\sim6$ | $\leq 10^3$ | $\leq 10^9$ | None |
| $7\sim10$ | $\leq 10^6$ | $\leq 10^6$ | None |
| $11\sim14$ | $\leq 10^6$ | $\leq 10^9$ | All $b_i$ are equal |
| $15\sim20$ | $\leq 10^6$ | $\leq 10^9$ | None |
Constraints: for all testdata, $1 \leq n \leq 10^6$, $1 \leq a_i,b_i \leq 10^9$.
Translated by ChatGPT 5