308308: CF1497D. Genius
Memory Limit:32 MB
Time Limit:2 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Genius
题意翻译
## 题目描述 注意内存限制 $n$个问题从$i$到$n$编号, 第$i$个问题给出 $c_i=2^i$, $tag_i$, $s_i$ 解决问题$i$后解决问题$j$条件是: $IQ<|c_i-c_j|$且$tag_i\neq tag_j$ 在解决完$i$后解决了$j$, 你的$IQ$变为$IQ=|c_i-c_j|$, 同时获得$|s_i-s_j|$分 问题解决的次数和顺序不受限制 一开始$IQ=0$, 求最高可获得的分数 ## 输入格式 第一行一个$t(1\leq t\leq 100)$, 表示数据组数 每组数据第一行一个$n(1\leq n\leq 5000)$,表示问题个数 第二行$n$个数, 表示$tag_i$ 第三行$n$个数 表示$s_i(1\leq s_i\leq 10^9)$ 保证$\sum n\leq5000$ ## 输出格式 $t$行, 每行一个数, 表示该组数据最高得分题目描述
Please note the non-standard memory limit. There are $ n $ problems numbered with integers from $ 1 $ to $ n $ . $ i $ -th problem has the complexity $ c_i = 2^i $ , tag $ tag_i $ and score $ s_i $ . After solving the problem $ i $ it's allowed to solve problem $ j $ if and only if $ \text{IQ} < |c_i - c_j| $ and $ tag_i \neq tag_j $ . After solving it your $ \text{IQ} $ changes and becomes $ \text{IQ} = |c_i - c_j| $ and you gain $ |s_i - s_j| $ points. Any problem can be the first. You can solve problems in any order and as many times as you want. Initially your $ \text{IQ} = 0 $ . Find the maximum number of points that can be earned.输入输出格式
输入格式
The first line contains a single integer $ t $ $ (1 \le t \le 100) $ — the number of test cases. The first line of each test case contains an integer $ n $ $ (1 \le n \le 5000) $ — the number of problems. The second line of each test case contains $ n $ integers $ tag_1, tag_2, \ldots, tag_n $ $ (1 \le tag_i \le n) $ — tags of the problems. The third line of each test case contains $ n $ integers $ s_1, s_2, \ldots, s_n $ $ (1 \le s_i \le 10^9) $ — 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