题库练习 Heavy Intervals
← 上一题 下一题 →

A16446 | Heavy Intervals

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

[Shiki - Pure Ruby](https://soundcloud.com/shiki-8/pure-rubyversoundcloud)

⠀



You have $n$ intervals $[l_1, r_1], [l_2, r_2], \dots, [l_n, r_n]$ , such that $l_i < r_i$ for each $i$ , and all the endpoints of the intervals are distinct.

The $i$ -th interval has weight $c_i$ per unit length. Therefore, the weight of the $i$ -th interval is $c_i \cdot (r_i - l_i)$ .

You don't like large weights, so you want to make the sum of weights of the intervals as small as possible. It turns out you can perform all the following three operations:

- rearrange the elements in the array $l$ in any order;
- rearrange the elements in the array $r$ in any order;
- rearrange the elements in the array $c$ in any order.

However, after performing all of the operations, the intervals must still be valid (i.e., for each $i$ , $l_i < r_i$ must hold).

What's the minimum possible sum of weights of the intervals after performing the operations?

输入格式

Each test contains multiple test cases. The first line contains the number of test cases $t$ ( $1 \le t \le 10^4$ ). The description of the test cases follows.

The first line of each test case contains a single integer $n$ ( $1 \le n \le 10^5$ ) — the number of intervals.

The second line of each test case contains $n$ integers $l_1, l_2, \ldots, l_n$ ( $1 \le l_i \le 2 \cdot 10^5$ ) — the left endpoints of the initial intervals.

The third line of each test case contains $n$ integers $r_1, r_2, \ldots, r_n$ ( $l_i < r_i \le 2 \cdot 10^5$ ) — the right endpoints of the initial intervals.

It is guaranteed that $\{l_1, l_2, \dots, l_n, r_1, r_2, \dots, r_n\}$ are all distinct.

The fourth line of each test case contains $n$ integers $c_1, c_2, \ldots, c_n$ ( $1 \le c_i \le 10^7$ ) — the initial weights of the intervals per unit length.

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$ .

输出格式

For each test case, output a single integer: the minimum possible sum of weights of the intervals after your operations.

输入输出样例

输入 #1
2
2
8 3
12 23
100 100
4
20 1 2 5
30 4 3 10
2 3 2 3
输出 #1
2400
42
C++ 编辑器
输入
输出