CF1497D.Genius
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Please note the non-standard memory limit.
There are n problems numbered with integers from 1 to n . i -th problem has the complexity ci=2i , tag tagi and score si .
After solving the problem i it's allowed to solve problem j if and only if IQ<∣ci−cj∣ and tagi=tagj . After solving it your IQ changes and becomes IQ=∣ci−cj∣ and you gain ∣si−sj∣ points.
Any problem can be the first. You can solve problems in any order and as many times as you want.
Initially your IQ=0 . Find the maximum number of points that can be earned.
输入格式
The first line contains a single integer t (1≤t≤100) — the number of test cases.
The first line of each test case contains an integer n (1≤n≤5000) — the number of problems.
The second line of each test case contains n integers tag1,tag2,…,tagn (1≤tagi≤n) — tags of the problems.
The third line of each test case contains n integers s1,s2,…,sn (1≤si≤109) — scores of the problems.
It's guaranteed that sum of n over all test cases does not exceed 5000 .
输出格式
For each test case print a single integer — the maximum number of points that can be earned.
输入输出样例
输入#1
5 4 1 2 3 4 5 10 15 20 4 1 2 1 2 5 10 15 20 4 2 2 4 1 2 8 19 1 2 1 1 6 9 1 1 666
输出#1
35 30 42 0 0
说明/提示
In the first test case optimal sequence of solving problems is as follows:
- 1→2 , after that total score is 5 and IQ=2
- 2→3 , after that total score is 10 and IQ=4
- 3→1 , after that total score is 20 and IQ=6
- 1→4 , after that total score is 35 and IQ=14
In the second test case optimal sequence of solving problems is as follows:
- 1→2 , after that total score is 5 and IQ=2
- 2→3 , after that total score is 10 and IQ=4
- 3→4 , after that total score is 15 and IQ=8
- 4→1 , after that total score is 35 and IQ=14
In the third test case optimal sequence of solving problems is as follows:
- 1→3 , after that total score is 17 and IQ=6
- 3→4 , after that total score is 35 and IQ=8
- 4→2 , after that total score is 42 and IQ=12