A14078 | Genius
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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$ .
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
In the first test case optimal sequence of solving problems is as follows:
1. $1 \rightarrow 2$ , after that total score is $5$ and $\text{IQ} = 2$
2. $2 \rightarrow 3$ , after that total score is $10$ and $\text{IQ} = 4$
3. $3 \rightarrow 1$ , after that total score is $20$ and $\text{IQ} = 6$
4. $1 \rightarrow 4$ , after that total score is $35$ and $\text{IQ} = 14$
In the second test case optimal sequence of solving problems is as follows:
1. $1 \rightarrow 2$ , after that total score is $5$ and $\text{IQ} = 2$
2. $2 \rightarrow 3$ , after that total score is $10$ and $\text{IQ} = 4$
3. $3 \rightarrow 4$ , after that total score is $15$ and $\text{IQ} = 8$
4. $4 \rightarrow 1$ , after that total score is $35$ and $\text{IQ} = 14$
In the third test case optimal sequence of solving problems is as follows:
1. $1 \rightarrow 3$ , after that total score is $17$ and $\text{IQ} = 6$
2. $3 \rightarrow 4$ , after that total score is $35$ and $\text{IQ} = 8$
3. $4 \rightarrow 2$ , after that total score is $42$ and $\text{IQ} = 12$
1. $1 \rightarrow 2$ , after that total score is $5$ and $\text{IQ} = 2$
2. $2 \rightarrow 3$ , after that total score is $10$ and $\text{IQ} = 4$
3. $3 \rightarrow 1$ , after that total score is $20$ and $\text{IQ} = 6$
4. $1 \rightarrow 4$ , after that total score is $35$ and $\text{IQ} = 14$
In the second test case optimal sequence of solving problems is as follows:
1. $1 \rightarrow 2$ , after that total score is $5$ and $\text{IQ} = 2$
2. $2 \rightarrow 3$ , after that total score is $10$ and $\text{IQ} = 4$
3. $3 \rightarrow 4$ , after that total score is $15$ and $\text{IQ} = 8$
4. $4 \rightarrow 1$ , after that total score is $35$ and $\text{IQ} = 14$
In the third test case optimal sequence of solving problems is as follows:
1. $1 \rightarrow 3$ , after that total score is $17$ and $\text{IQ} = 6$
2. $3 \rightarrow 4$ , after that total score is $35$ and $\text{IQ} = 8$
3. $4 \rightarrow 2$ , after that total score is $42$ and $\text{IQ} = 12$
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted