CF1497D.Genius

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:32MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Please note the non-standard memory limit.

There are nn problems numbered with integers from 11 to nn. ii-th problem has the complexity ci=2ic_i = 2^i, tag tagitag_i and score sis_i.

After solving the problem ii it's allowed to solve problem jj if and only if IQ<∣ci−cj∣\text{IQ} \lt |c_i - c_j| and tagi≠tagjtag_i \neq tag_j. After solving it your IQ\text{IQ} changes and becomes IQ=∣ci−cj∣\text{IQ} = |c_i - c_j| and you gain ∣si−sj∣|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 IQ=0\text{IQ} = 0. Find the maximum number of points that can be earned.

请注意非标准的内存限制。

共有 nn 道题目,编号为 11 到 nn。第 ii 道题的难度为 ci=2ic_i = 2^i,标签为 tagitag_i,分值为 sis_i。

在解出题目 ii 后,当且仅当满足 IQ<∣ci−cj∣\text{IQ} \lt |c_i - c_j| 且 tagi≠tagjtag_i \neq tag_j 时,才允许解题目 jj。解出题目 jj 后,你的 IQ\text{IQ} 将更新为 IQ=∣ci−cj∣\text{IQ} = |c_i - c_j|,并获得 ∣si−sj∣|s_i - s_j| 分。

任意一道题均可作为起始题目。你可以以任意顺序、任意次数求解题目。

初始时你的 IQ=0\text{IQ} = 0。求最多能获得的分数。

输入格式

The first line contains a single integer tt (1≤t≤100)(1 \le t \le 100) — the number of test cases.

The first line of each test case contains an integer nn (1≤n≤5000)(1 \le n \le 5000) — the number of problems.

The second line of each test case contains nn integers tag1,tag2,…,tagntag_1, tag_2, \ldots, tag_n (1≤tagi≤n)(1 \le tag_i \le n) — tags of the problems.

The third line of each test case contains nn integers s1,s2,…,sns_1, s_2, \ldots, s_n (1≤si≤109)(1 \le s_i \le 10^9) — scores of the problems.

It's guaranteed that sum of nn over all test cases does not exceed 50005000.

第一行包含一个整数 tt(1≤t≤1001 \le t \le 100)—— 测试用例的数量。

每个测试用例的第一行包含一个整数 nn(1≤n≤50001 \le n \le 5000)—— 问题的数量。

每个测试用例的第二行包含 nn 个整数 tag1,tag2,…,tagntag_1, tag_2, \ldots, tag_n(1≤tagi≤n1 \le tag_i \le n)—— 各问题的标签。

每个测试用例的第三行包含 nn 个整数 s1,s2,…,sns_1, s_2, \ldots, s_n(1≤si≤1091 \le s_i \le 10^9)—— 各问题的分数。

保证所有测试用例中 nn 的总和不超过 50005000。

输出格式

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. 1→21 \rightarrow 2, after that total score is 55 and IQ=2\text{IQ} = 2
  2. 2→32 \rightarrow 3, after that total score is 1010 and IQ=4\text{IQ} = 4
  3. 3→13 \rightarrow 1, after that total score is 2020 and IQ=6\text{IQ} = 6
  4. 1→41 \rightarrow 4, after that total score is 3535 and IQ=14\text{IQ} = 14

In the second test case optimal sequence of solving problems is as follows:

  1. 1→21 \rightarrow 2, after that total score is 55 and IQ=2\text{IQ} = 2
  2. 2→32 \rightarrow 3, after that total score is 1010 and IQ=4\text{IQ} = 4
  3. 3→43 \rightarrow 4, after that total score is 1515 and IQ=8\text{IQ} = 8
  4. 4→14 \rightarrow 1, after that total score is 3535 and IQ=14\text{IQ} = 14

In the third test case optimal sequence of solving problems is as follows:

  1. 1→31 \rightarrow 3, after that total score is 1717 and IQ=6\text{IQ} = 6
  2. 3→43 \rightarrow 4, after that total score is 3535 and IQ=8\text{IQ} = 8
  3. 4→24 \rightarrow 2, after that total score is 4242 and IQ=12\text{IQ} = 12

在第一个测试用例中,解决问题的最优序列为:

  1. 1→21 \rightarrow 2,之后总得分为 55,IQ=2\text{IQ} = 2
  2. 2→32 \rightarrow 3,之后总得分为 1010,IQ=4\text{IQ} = 4
  3. 3→13 \rightarrow 1,之后总得分为 2020,IQ=6\text{IQ} = 6
  4. 1→41 \rightarrow 4,之后总得分为 3535,IQ=14\text{IQ} = 14

在第二个测试用例中,解决问题的最优序列为:

  1. 1→21 \rightarrow 2,之后总得分为 55,IQ=2\text{IQ} = 2
  2. 2→32 \rightarrow 3,之后总得分为 1010,IQ=4\text{IQ} = 4
  3. 3→43 \rightarrow 4,之后总得分为 1515,IQ=8\text{IQ} = 8
  4. 4→14 \rightarrow 1,之后总得分为 3535,IQ=14\text{IQ} = 14

在第三个测试用例中,解决问题的最优序列为:

  1. 1→31 \rightarrow 3,之后总得分为 1717,IQ=6\text{IQ} = 6
  2. 3→43 \rightarrow 4,之后总得分为 3535,IQ=8\text{IQ} = 8
  3. 4→24 \rightarrow 2,之后总得分为 4242,IQ=12\text{IQ} = 12

输入解题思路,AI测评打分。不知道怎么写?

首页