CF1909C.Heavy Intervals
普及/提高-
通过率:0%

AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
⠀
You have n intervals [l1,r1],[l2,r2],…,[ln,rn] , such that li<ri for each i , and all the endpoints of the intervals are distinct.
The i -th interval has weight ci per unit length. Therefore, the weight of the i -th interval is ci⋅(ri−li) .
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 , li<ri 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≤t≤104 ). The description of the test cases follows.
The first line of each test case contains a single integer n ( 1≤n≤105 ) — the number of intervals.
The second line of each test case contains n integers l1,l2,…,ln ( 1≤li≤2⋅105 ) — the left endpoints of the initial intervals.
The third line of each test case contains n integers r1,r2,…,rn ( li<ri≤2⋅105 ) — the right endpoints of the initial intervals.
It is guaranteed that {l1,l2,…,ln,r1,r2,…,rn} are all distinct.
The fourth line of each test case contains n integers c1,c2,…,cn ( 1≤ci≤107 ) — the initial weights of the intervals per unit length.
It is guaranteed that the sum of n over all test cases does not exceed 105 .
输出格式
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
说明/提示
In the first test case, you can make
- l=[8,3] ;
- r=[23,12] ;
- c=[100,100] .
In that case, there are two intervals:
- interval [8,23] with weight 100 per unit length, and 100⋅(23−8)=1500 in total;
- interval [3,12] with weight 100 per unit length, and 100⋅(12−3)=900 in total.
The sum of the weights is 2400 . It can be shown that there is no configuration of final intervals whose sum of weights is less than 2400 .
In the second test case, you can make
- l=[1,2,5,20] ;
- r=[3,4,10,30] ;
- c=[3,3,2,2] .
In that case, there are four intervals:
- interval [1,3] with weight 3 per unit length, and 3⋅(3−1)=6 in total;
- interval [2,4] with weight 3 per unit length, and 3⋅(4−2)=6 in total;
- interval [5,10] with weight 2 per unit length, and 2⋅(10−5)=10 in total;
- interval [20,30] with weight 2 per unit length, and 2⋅(30−20)=20 in total.
The sum of the weights is 42 . It can be shown that there is no configuration of final intervals whose sum of weights is less than 42 .